Comments (14)
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.
@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.
Do you mean the image meta wasn't brought over or the post meta referenced the wrong image ID?
from distributor.
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.
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.
@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.
@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.
PR created for this issue, #84
from distributor.
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!
from distributor.
@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.
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.
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.
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.
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)
- `dt_available_pull_post_types` Filter Not Working
- Product disconnect HOT 2
- Shipping rates on woocommerce
- May a typo in NetworkSiteConnection.php HOT 1
- Featured Image Not Pulling HOT 3
- Woocommerce images wrong transfer HOT 1
- i Cant connect my both sites HOT 1
- WordPress REST API Authentication plugin makes the disturbuter plguin do not work
- The plugin hasn't been tested with the latest version of WordPress HOT 1
- Distributor throws an error in WordPress 6.5 RC 3's new synced patterns editor HOT 1
- Registration validity indicator not displaying
- Filter Connection By Category
- Unable to access password protected site.
- Member only post content?
- Original date not used on pull (after use of snippet)
- Image Issues
- Getting an error on workpress post update of "Uncaught Error: Call to undefined function Distributor\InternalConnections\get_site()"
- Able to push and pull content from one site but not the other HOT 6
- Fatal error when pushing item HOT 3
- mapping to different categories possible? HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from distributor.