Tell us what you are trying to do?
I'm following on from a recent support request. I thought we had it working perfectly but further testing reveals a small issue in the code!
The first part works fine: it gets course posts attached to the user profile. I added a "1" with array_push just in case there are no posts:
if($user_profile_posts[0]){
$user_course_query = new WP_Query(
array(
'post_type' => 'corso', // "Course" post type slug
'toolset_relationships' => array(
'role' => 'parent',
'related_to' => $user_profile_posts[0],
'relationship' => 'corso-profilo-utente' // Relationship slug between "course" and "user-profile"
),
'posts_per_page' => -1,
'fields' => 'ids'
)
);
$course_posts = $user_course_query->posts;
array_push($course_posts,"1");
}
The second part then gets subject posts that are attached to course posts from the first part. It works, but only for the first value in the array - [0]. The initial code which I copied was for a single user profile CPT, but now we have multiple courses that can be added to the profile CPT, and I want to return an array of subject posts attached to all attached course posts - not just the first one.
In the following code how can I change: 'related_to' => $course_posts[0], to accept all course posts from the code above and not just the first?
Thank you!
if($course_posts){
$course_subject_query = new WP_Query(
array(
'post_type' => 'argomento', // "Subject" post type slug
'toolset_relationships' => array(
'role' => 'child',
'related_to' => $course_posts[0],
'relationship' => 'corso-argomento' // Relationship slug between "course" and "subject"
),
'posts_per_page' => -1,
'fields' => 'ids'
)
);
$course_subject_posts = $course_subject_query->posts;
}
Thanks so much Minesh! - it works great. I have updated the code in the following Google doc if anyone is interested in this method of content restriction:
hidden link
I also summarised the main ways to restrict content in Toolset here: