I have a website for a training academy. I have a Lecturer CPT and a Course CPT. In the single-course.php file, I am loading Lecturers related to that Course.
Course with related Lecturer: hidden link
Course without related Lecturer, still showing title: hidden link
Here's my feeble attempt:
<?PHP
$course_id = get_the_ID();
$related_lecturers = toolset_get_related_posts(
$course_id, // get posts related to this one
'course-lecturer', // relationship between the posts
'parent', // get posts where $writer is the parent in given relationship
100, 0, // pagination
array(), // How was his surname, again…?
'post_object',
'child'
);
?>
Ideally we would like to test each step of the way. Given that your algorithm is heavily dependent on the $related_lecturers value being correct my advice here is to dump the value of that field on the page to ensure that you're getting the correct value.
Add this to your code to see what the $related_lecturers is returning.
var_dump($related_lecturers);
However I believe the correct way to structure the relationship function is like below.
I don't think I explained myself well. The code I have is working.
I just want to be able to display a title for this section depending on if there are related posts or not. So basically, if there are posts, I want to display the following, before the grid of related posts.
I'm using the empty() function to check if the field is empty. However i'm negating the function with the "!" symbol which essentially reads If Not Empty. Adding it to the conditional will only show the items in the conditional field only if the value isn't empty.