"artist" is the parent post and "concord-albums" is the child.
I want to build a WP query string that can pull other related children of the current child post and list those at bottom of current post while excluding the current post.
For example I am looking at an album by an artist and I want to see all other albums by that artist at bottom of current post but exclude the current post.
Thanks so using the example you sent. If I have a cpt called "artist" (parent) and a cpt called "concord-albums" (child) and I want to show other children of same parent on a child cpt (so looking at one album, I want all related albums to parent of current child listed at bottom of current post)but want to exclude the current post it would look something like this?:
$query = new WP_Query(
array(
'post_type' => 'concord-albums,
'posts_per_page' => -1,
//new toolset_relationships query argument
'toolset_relationships' => array(
'role' => 'child',
'related_to' => get_the_ID(), WHAT GOES HERE? 'artist'?
// this will work only with relationships that have existed before the migration
// if possible, use the relationship slug instead of an array
'relationship' => array( 'artist, 'concord-albums' )
),
'order' => 'ASC',
)
);
$posts = $query->posts;
global $post;
$post_relationship_slug = 'personal-trainer-session'; // change the post relationship slug to your original post relationship slug
$parent_id = toolset_get_related_post($post->ID,$post_relationship_slug); // getting parent_id based on the current child post
$query = new WP_Query(
array(
'post_type' => 'concord-albums',
'posts_per_page' => -1,
'toolset_relationships' => array(
'role' => 'child',
'related_to' => $parent_id,
'relationship' => $post_relationship_slug, // slug of the post relationship
),
'order' => 'ASC',
'post__not_in' => array($post->ID), // excluding the current post
)
);
$found_posts = $query->posts;
echo "<pre>";
print_r($found_posts );
exit;
With $found_posts you will see the desired post array. You should loop through the $found_posts and display your posts as required.
Thank you this is great. I now am wondering how I can pull through the "Artist Name" which would be the $parent_id in this case. I am able to return the albums correctly but how can I grab the related artist name to show on front. I am not using views so that is not an option.