Attachments in custom fields
Let’s consider a situation when you have a custom field where you can upload an image or file. And the custom field doesn’t store file URL, but its ID. What should we do in this case, because on subsites where we about to crosspost to the file it may not exist or even if it exists, its ID most likely differs.
Below you can find free add-ons, which automatically copy attachments from custom fields to subsites and connect them.
In case you’re using a multisite version of the plugin, just install the add-on below and that’s it.
If you’re using a non-multisite version of the plugin, also feel free to install the add-on below, but before that don’t foget to configure metadata.
If you’re using ACF plugin, there is nothing else to do – add-on automatically recognizes the field types – Image, Gallery or File. In case you’re using any other plugin or a custom meta box, please add meta keys of attachment fields into a hook:
add_filter( 'rudr_crosspost_attachment_meta_keys', function( $meta_keys ) {
$meta_keys[] = 'my_image_field';
$meta_keys[] = 'post_bg_image_blah_blah';
// ... etc
return $meta_keys;
} );
If the fields, mentioned in the hook, store an attachment ID or an array of IDs, they are going to be processed:
- Attachment (or attachments) are going to be copied to sub-sites if necessary.
- The meta values will be replaced with the appropriate attachment IDs on sub-sites.