Using ACF Pro i have a CPT named Faculty with many Professors (another CPT). This is a one to many relationship field i have in the Faculty fields group. How can i display in the Professor single template the faculty that the professor belongs to ?
I have tried to create a query loop with the relationship on the type but it doesn’t work.
I have done so in JetEngine that relations are set seperately, but unfortunately i can’t do so in ACF Pro.
Any help?
Hi
I am using a lot of bidirectional relationship queries and since available, I have switched all of them to the query editor to get the data, because it also gives me the possibility to define other things like the sorting order directly in the query.
You can try this code yourself and replace recipes with your post type used (e.g. faculty) and from_the_cookings with your ACF relationship field (the one in the post type faculty that points to the Professors in the other CPT and that relationship ACF field):
return [
'post_type' => 'recipes', //e.g. faculty
'posts_per_page' => -1,
'meta_query' => array(
array(
'key' => 'from_the_cookings', // the ACF rel field
'value' => get_the_id(),
'compare' => 'LIKE'
)
),
'order' => 'ASC',
'orderby'=> 'title',
];
Make sure to leave the Query Type as Posts like in the picture above.
Cheers and good luck
Patric
Thank you for your help.
I am not really familiar with php (i can of course change the code you sent) but it is supposed to be much easier with a visual approach and not with the use of php.
Using the relationship in the query is supposed to return in the post title the name of the first part of the relationship.
What is wrong with my approach ?
Patric thank you so much.
It worked great !!
I still need some documantation though why it is not working visually without PHP, when it works fine with JetEngine.