Does Bricks support Pods relationships? Watching videos based on ACF it looks like Bricks adds a new type of query that can be based on the relationship, but nothing is showing up for me with Pods.
Specifically, I have a cpt called Programs, with a relationship field that links to another cpt called Courses. I want to be able to pull in a few courses on the single Program template based on that relationship.
I was able to sort of solve this using this code. Modified from this comment. That said, it works by using a relationship established by the course. It would be much better if I could set the relationship at the program and query from that. If anyone can help with this it would be appreciated!
If the relationship is bidirectional each course has a list of programs and each program has a list of courses (you can see these in the wp_postmeta table as serialized arrays of numbers). Assuming the relationship field is called ārelated_coursesā from the perspective of a program and ārelated_programsā from the perspective of a course (you can name them anything):
// Running on a program post ID
$ids = pods()->field( 'related_courses', [ 'output' => 'ids' ] ) ?: [ 0 ];
return [
'post_type' => 'course',
'posts_per_page' => -1,
'post__in' => $ids,
'order' => 'ASC',
'orderby'=> 'post__in' // if you wanted to sort by position set in the UI
];
I think you can still do it using a meta query though (with fewer database calls):
return [
'post_type' => 'course',
'posts_per_page' => -1,
'meta_query' => [
[
'key' => 'related_courses', // The relationship field
'value' => 'i:'. get_the_ID() . ';', // Program ID
'compare' => 'LIKE'
]
],
'order' => 'ASC',
'orderby'=> 'title'
];