Giter Club home page Giter Club logo

Comments (14)

ulkish avatar ulkish commented on May 14, 2024 1

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

from distributor.

jeffpaul avatar jeffpaul commented on May 14, 2024 1

@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!

from distributor.

tlovett1 avatar tlovett1 commented on May 14, 2024

Do you mean the image meta wasn't brought over or the post meta referenced the wrong image ID?

from distributor.

jasonbahl avatar jasonbahl commented on May 14, 2024

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.

from distributor.

adamsilverstein avatar adamsilverstein commented on May 14, 2024

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.

from distributor.

goranseric avatar goranseric commented on May 14, 2024

@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.

from distributor.

goranseric avatar goranseric commented on May 14, 2024

@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.

from distributor.

goranseric avatar goranseric commented on May 14, 2024

PR created for this issue, #84

from distributor.

meredevelopment avatar meredevelopment commented on May 14, 2024

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:

image

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!

from distributor.

FilNunes avatar FilNunes commented on May 14, 2024

@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 ?

from distributor.

rg- avatar rg- commented on May 14, 2024

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.

from distributor.

jeffpaul avatar jeffpaul commented on May 14, 2024

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.

from distributor.

thedavidthomas avatar thedavidthomas commented on May 14, 2024

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

from distributor.

crysbue07 avatar crysbue07 commented on May 14, 2024

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.

from distributor.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.