Hi,
In the caveats, there is a note regarding post meta associations, specifying that these will not be "brought along" in transfers. As I am developing a network of sites with complex relational metadata (using ACF), I have two questions:
Thanks in advance!
Hi @john-lynch-cp, we have some internal discussion on this topic but we haven't had a final direction yet.
The saved meta value is the ID of related object, which is different between the original and remote sites. You can solve this issue by replacing the object ID (the meta value) by the correct one on the remote site:
dt_connection_map
meta that can be used to retrieve the remote post id.You can prepare the post meta (change post id, add term slug, add user login) by hooking to dt_push_post_args
and dt_subscription_post_args
.
To update the correct meta value on the remote site, hook to dt_process_distributor_attributes
and dt_process_subscription_attributes
.
For your questions:
The note references "push" transfers. Is the same true of "pull" requests?
The short answer is no, push and pull are different. While it's possible to achieve the same result of push using pull, you'll need some additional steps to prepare post meta. For push
, because you're the original site, you can prepare additional meta data before pushing. But you can't do the same with pull
. Distributor uses posts endpoint to get the post data for pull
, see this.
Is there an example available of the "case by case" extension of the plugin which is suggested? I'd be keen to give this a try but don't know where to start!
For example, you have a taxonomy field (using ACF), named test_meta
, which links to project_category
taxonomy. Please note that the example below is made for education purpose only, it's not an optimal solution.
add_action( 'dt_push_post_args', 'prepare_meta', 10, 2 );
function prepare_meta( $post_body, $post ) {
$term_id = get_post_meta( $post->ID, 'test_meta', true );
if( $term_id ) {
$term = get_term_by( 'id', $term_id, 'project_category');
$post_body['project_category_slug'] = $term->slug;
}
return $post_body;
}
add_action( 'dt_process_distributor_attributes', 'set_meta', 10, 2 );
function set_meta( $post, $request ) {
$term = get_term_by( 'slug', $request['project_category_slug'], 'project_category' );
if ( ! $term ) {
return;
}
update_post_meta( $post->ID, 'test_meta', $term->term_id );
}
Btw, there is an addons made by Novembit which is similar to the example above but more complicated: https://github.com/NovemBit/distributor-acf-addon. Note that this addon is not compatible with the current version of Distributor.
Hope this help!
@john-lynch-cp does the response above resolve your questions such that we can close out this issue or do you have any follow-up questions?
Thanks for the follow up, happy for you to close this out right now. I think we're looking toward a different CMS as the distribution challenge might make more sense with a different approach.
Most helpful comment
Hi @john-lynch-cp, we have some internal discussion on this topic but we haven't had a final direction yet.
The saved meta value is the ID of related object, which is different between the original and remote sites. You can solve this issue by replacing the object ID (the meta value) by the correct one on the remote site:
dt_connection_map
meta that can be used to retrieve the remote post id.You can prepare the post meta (change post id, add term slug, add user login) by hooking to
dt_push_post_args
anddt_subscription_post_args
.To update the correct meta value on the remote site, hook to
dt_process_distributor_attributes
anddt_process_subscription_attributes
.For your questions:
The short answer is no, push and pull are different. While it's possible to achieve the same result of push using pull, you'll need some additional steps to prepare post meta. For
push
, because you're the original site, you can prepare additional meta data before pushing. But you can't do the same withpull
. Distributor uses posts endpoint to get the post data forpull
, see this.For example, you have a taxonomy field (using ACF), named
test_meta
, which links toproject_category
taxonomy. Please note that the example below is made for education purpose only, it's not an optimal solution.Btw, there is an addons made by Novembit which is similar to the example above but more complicated: https://github.com/NovemBit/distributor-acf-addon. Note that this addon is not compatible with the current version of Distributor.
Hope this help!