I tried many different combinations and variants with double- or single-quotes and couldn't get any to work where the wpv-view shortcode was correctly parsed when having a non-Toolset shortcode to supply a shortcode attribute.
I suggest you re-think your approach, and instead of nesting the shortcodes in the way you describe to provide attributes for the View, you use the Views API to modify the View to achieve the same effect.
I wanted a view with fields from an intermediary relationship. I coudn't get it right. So i made an view with the ID set by the View shortcode attribute "ids" as filter...
It works now, but can this be done easier?
// Add Shortcode
function img_relatieid( ) {
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' );
The documentation is a little opaque. I'll have to set up a test to verify how to retrieve an intermediate post ID when you have the IDs of both end posts, that's what we are aiming for, correct?
(You might be able to output fields from the intermediate posts without special code using a View that is set to query the intermediate post type if you can add Query Filters for both ends of the relationship.)
Yes please, can you setup a test? A test to verify how to retrieve an intermediate post ID when you have the IDs of both end posts, that's what we are aiming for.
I was able to get it working with the following code:
$left_id = 168;
$right_id = 169;
// get the intermediate post(s) between these two posts
$intermediate_ids = toolset_get_related_posts(
array( 'parent' => array($left_id), 'child' => array($right_id) ), // origin post ID(s)
'left-right', // slug of relationship
array ('role_to_return' => 'intermediary')
);
error_log('intermediate_ids: ' . print_r($intermediate_ids, true));
I have a m2m relationship between "left" posts and "right" posts.
So using tooset_get_related_posts as described here will return the intermediate post ID (as an array, so the actual ID of the intermediate post would be $intermediate_ids[0]).
You'll obviously have to adapt this to your needs.