Attachments in Custom Fields

Let’s imagine a situation when you have a custom field where you can upload an image or file. And the custom field doesn’t store a file URL, but its ID. What should we do in this case, because on subsites, where we about to crosspost to, the file may not exist or even if it exists, its ID most likely will be different.

If you’re using ACF, you just need to install and activate an add-on from here.

But what to do if your custom fields aren’t created with ACF? Maybe they are created with any other custom fields plugin or maybe even coded directly in your theme.

In that case please install one of the add-ons below depending on which plugin you’re using.

For Simple WP Crossposting:

Download Simple WP Crossposting – Attachments in Custom Fields 3.2

For Simple Multisite Crossposting:

Download Simple Multisite Crossposting – Attachments in Custom Fields 4.1

The last but not the least, let’s decide under what meta keys our attachment IDs are stored in the database. Let’s say the keys are my_image_field and post_bg_image_blah_blah.

In that case you need to use the following snippet:

add_filter( 'rudr_crosspost_attachment_meta_keys', function( $meta_keys ) {
	// add first field
	$meta_keys[] = 'my_image_field';
	// add second field
	$meta_keys[] = 'post_bg_image_blah_blah';

	return $meta_keys;
} );

The snippet should be inserted to “Site 1” – the site you’re about to crosspost from. In case you don’t know how – please read this.

Just to double check, after using the snippets above:

  1. Attachment (or attachments) are going to be copied to sub-sites if necessary.
  2. The meta values will be replaced with the appropriate attachment IDs on sub-sites.

If something is not 100% clear for you, please watch the video below:

Need more help?