Patch: Convert Custom Fields pointing to attachments
-
Hey Edward,
I have a number of custom post formats that contain custom fields pointing to attachments. So for instance I have a “Photos” post format that contains three thumbnails, which are attached by custom fields (creatively named “image1”, “image2”, and “image3”).
While the Broadcast plugin correctly finds these attachments and moves them over to the correct blog, the post IDs are not updated in the custom fields. This creates some more work for my users who then have to go into the gallery, figure out which images were originally attached, and re-attach them.
Rather than deal with all of that junk, I fixed the plugin. Essentially it will search the post’s custom fields for IDs that were pointing to attachments, and convert them. I’m not sure of the best way to submit this, so I’m just going to attach some code:
At line 1541: (just past
wp_delete_attachment( $attachment_to_remove->ID
);$converted_attachment_IDs = array(); foreach( $attachment_data as $key=>$attached_file) { if ( $key != 'thumbnail' ) $converted_attachment_IDs[$key] = $this->copy_attachment( $attached_file, $new_post_id ); }
At line 1567: (just past
$single_meta_value = maybe_unserialize( $single_meta_value );
)// If this was a custom field pointing to an attachment, convert the ID if(array_key_exists($single_meta_value, $converted_attachment_IDs)){ $single_meta_value = $converted_attachment_IDs[$single_meta_value]; }
At line 1574: (just past
$meta_value = maybe_unserialize( $meta_value );
)// If this was a custom field pointing to an attachment, convert the ID if(array_key_exists($meta_value, $converted_attachment_IDs)){ $meta_value = $converted_attachment_IDs[$meta_value]; }
Let me know if this makes sense – I have subbed to email notifications on this thread so I will get the messages & can send the full file / a patch if needed.
https://www.ads-software.com/extend/plugins/threewp-broadcast/
- The topic ‘Patch: Convert Custom Fields pointing to attachments’ is closed to new replies.