I’ve inherited an imported wordpress site with a few issue. I have a list of attahment ids and post ids but I need to re-connect them in the code.
I’ve got a list of all attachemnt like this:
$attachments = get_posts( array('post_type' => 'attachment','posts_per_page' => -1));
foreach ( $attachments as $key=>$attachment ) {
}
I’ve also got a csv of attachment ids, and which post they relate to. Now all the attahment parent post ids are ‘0’, what i need to do is update each one so it’s parnet post id is the related id in
What’s the key wordpress function in this loop set an attachemnts parnet post id? And then make sure that update is propagated to all the meta data too.
I want something like….
set_attachemnt_parent_id($attachment->ID, $myIdFromArchives);
Thanks for your help!
Edit – I have tried doing a direct update of the database id but that doesn’t work.