Can you help me? the relationships in toolset has changed also in the database. Previously I had below shortcode to get the intermediary_id back. How do I do that now? Is there a new shortcode for that?
// Add Shortcode
function img_relatieid( $atts ) {
// Attributes
$atts = shortcode_atts(
array(
'loc' => '5807',
'prod' => '354',
),
$atts
);
global $wpdb;
$table_name = $wpdb->prefix . "toolset_associations";
$locatie = do_shortcode('[wpv-post-id]');
$product = do_shortcode('[wpv-post-id item="$current_page"]');
$relatieid = $wpdb->get_results("SELECT * FROM $table_name WHERE parent_id = $product AND child_id = $locatie");
if (count($relatieid)> 0){
foreach ($relatieid as $row) {
return $row->intermediary_id;
}
} else {
return 9999;
}
}
add_shortcode( 'imgrelatieid', 'img_relatieid' );
Hi,
Thank you for contacting us and I'd be happy to assist.
It has been quite a while since the post-relationship structure has been changed, which is why this old shortcode no longer works.
To get the related 'intermediary' post ID, when 'parent' and 'child' post ID is known, you can use the "toolset_get_related_posts" function in your shortcode:
https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/#toolset_get_related_posts
For example:
// Add Shortcode
function img_relatieid( $atts ) {
// Attributes
$atts = shortcode_atts(
array(
'loc' => '5807',
'prod' => '354',
'rel_slug' => '',
),
$atts
);
$locatie = do_shortcode('[wpv-post-id]');
$product = do_shortcode('[wpv-post-id item="$current_page"]');
$relationship_slug = $atts['rel_slug'];
// Get the related 'intermediary' post
$relatieid = toolset_get_related_posts(
[
'parent' => $product,
'child' => $locatie
],
$relationship_slug,
[
'role_to_return' => 'intermediary'
]
);
if (count($relatieid)> 0) {
foreach ($relatieid as $item) {
return $item;
}
} else {
return 9999;
}
}
add_shortcode( 'imgrelatieid', 'img_relatieid' );
Note: To use this updated shortcode, you'll need to provide the relationship's slug, in the 'rel_slug' attribute, like this:
[imgrelatieid rel_slug="product-location"]
You'll replace 'product-location' with the actual slug of your relationship.
I hope this helps and for more personalized assistance around custom code, you can also consider hiring a professional from our list of recommended contractors:
https://toolset.com/contractors/
regards,
Waqar
My issue is resolved now. Thank you!