distributor
distributor copied to clipboard
ACF content not distributed
I am using Distributor on a complex multisite installation serving landing page builder developed using ACF as the foundation.
We are handling images on sites via Delicious Brains WP Offload S3 plugin and when distributing a page, it copies all fields correctly except the image fields (possibly related to https://github.com/10up/distributor/issues/77). The physical image is copied over to the destination site, with correct S3 URL, but it is not tied to the field, the image field is always empty.
I have distributed a dozen of posts and the image field was newer properly populated.
So far this is the only issue I have stumbled upon after using the plugin for a while in a pretty complex environment. Great job.
Do you mean the image meta wasn't brought over or the post meta referenced the wrong image ID?
My bad, meant to submit a comment, not close the issue.
I believe there will need to be a hook added on the incoming site to update the reference for the custom meta.
Distributor doesn't know about all references stored in meta, so when the post is created on the distributed site, you could hook into something like updated_post_meta
for a certain meta_key, and do the transformation to get the ID to relate to the proper image.
We already handle moving over feature images and plugins can likely leverage or follow that functionality. Some documentation and code examples showing how to do that for both images and other id-related items would be great.
@tlovett1 I have looked into this a bit more today and I have found out that wrong image ID is referenced. The problem is that process_media function, returns the media ID that is not updated within the data that was distributed and old image remains but it is nonexistent (or the wrong image will be displayed) on new site.
@jasonbahl I agree on that, it is impossible to cover everything in Distributor and there will be definitely lots of situations when corrections will be made via hooks. It would be good to add media meta field that contains old image id from the original site, as it would make things easier to find the new image ID and update the old image ID with correct one.
PR created for this issue, https://github.com/10up/distributor/pull/84
Thanks for adding the dt_original_media_id
meta @goranseric. I'm attempting to implement it. I'm not sure exactly how you intend it to work. The code below partially works. I'm watching for added and updated dt_original_media_id
keys, and then searching for all posts that have the meta_value in a specific ACF field called 'profile_picture':
function action_updated_post_meta($meta_id, $object_id, $meta_key, $_meta_value) {
if ('dt_original_media_id' == $meta_key) {
$args = array(
'post_type' => 'people',
'meta_key' => 'profile_picture',
'meta_value' => $_meta_value
);
$post_query = new WP_Query($args);
$posts = $post_query->get_posts();
foreach( $posts as $post ) {
//Set the post field to the new media ID.
update_post_meta($post->ID, 'profile_picture', $object_id);
//Add some debug data to another field.
update_post_meta($post->ID, 'person_description', "Values: $meta_id, $object_id, $meta_key, $_meta_value<br />Action: ".current_action());
}
}
}
add_action( 'updated_post_meta', 'action_updated_post_meta', 10, 4 );
add_action( 'added_post_meta', 'action_updated_post_meta', 10, 4 );
What works: Any posts that use the old media ID have the new media ID added. When I 'edit' the people post, the ACF field displays the correct image. You can also see from this screeny that the debug data has been added to the description field too:
Note though that the fields are not greyed as I'd expect them to be with Distributed posts.
What doesn't work (and is a show-stopper) On the front-end, the profile image hasn't been updated. If I edit the people post, and click 'Update', the media item gets saved, and then appears as it should.
It's almost as though the update has been done, but I'd need to manually (programatically) save the post again to make it work.
If you have any thoughts on this @tlovett1 please chip in. I'm quite prepared for it to my stupid code that's the problem!
@tlovett1 I have looked into this a bit more today and I have found out that wrong image ID is referenced. The problem is that process_media function, returns the media ID that is not updated within the data that was distributed and old image remains but it is nonexistent (or the wrong image will be displayed) on new site.
I have the same problem ... any solution ?
Hey guys! About two months ago me and my boss encountered this issue and started digging into it. I think we finished it a couple weeks ago and forgot to post it here. There's room for improvement but it works in my tests. Anyways here you go: https://github.com/ulkish/distribute-acf-images
@ulkish thanks for the contribution, it's greatly appreciated! We've got this milestoned for the 2.0.0 release later this year, so I'll get back to you on any questions as the team gets into reviewing issues/PRs for that release, thanks!
Hey, notice this is some old, but i discovered that all this stuff is solved using:
update_field('YOUR_FIELD_KEY', 'NEW_VALUE', $POST_OBJECT);
So, considerations when updating an image field:
- do not use update_post_meta(),
- use field KEY, not name,
- use Post object, not post ID.
Noting here that as we get into implementing and testing a fix for handling ACF (and similar plugins), we will want to review the linked and closed issues for additional insight on use cases and potential fixes.
I'm using an External Connection.
Is there anything in prepare_media
to add additional ACF Image ID fields?
I've managed to add to distributor_media
in the rest endpoint via rest_prepare_post
and the initial pull is adding images into the media library of site B and using the updated_post_meta/added_post_meta
(@meredevelopment's solution) is finding the fields using those original image ID's and updating according
This works great until the original post is updated then the old ID's are then getting pushed again by /wp/v2/dt_subscription/receive
Curious if there have been any updates to fixing the issues with media being pulled from ACF posts? When I try to sync content between two sister-branded sites, it's pulling random images from my media library instead of the images in the original post.