Also, structure is as follows:
The key is the ACF relationship field that is in the post type that is mentioned in the beginning of the code in line 2.
You are in the single post type template, right?
Currently, I am in the post type for the Game post type, and referencing the Post post type, the field that is in the Game post type that references posts is called : related_posts_and_reviews and the one in the posts is called: related_game_post
I hope that makes sense
Have you tried now the code above in the query editor?
It is not working for what ever reason. Thank you so much for the help, going to try the route of Taxonomy linked to a CPT.
Hi, maybe this will help you to check your setup:
I have a CPT called âcookingsâ (A1) for cooking events and a CPT called ârecipesâ (A2) for cooking recipes.
The CPT cookings (A1) has an ACF Relationship Field called âcooking_recipesâ (R1) which has a Bidirectional relation to the Target field called âfrom_the_cookingsâ (R2).
The CPT recipes (A2) has an ACF Relationship Field called âfrom_the_cookingsâ (R2) which has a Bidirectional relation to the Target field called âcooking_recipesâ (R1).
The single post type template for âcookingsâ has a custom query made with the Bricks query editor, which is as follows:
and the query in the query editor:
return [
'post_type' => 'recipes',
'posts_per_page' => -1,
'meta_query' => array(
array(
'key' => 'from_the_cookings',
'value' => get_the_id(),
'compare' => 'LIKE'
)
),
'order' => 'ASC',
'orderby'=> 'title',
];
So in other words, the single post type template for âcookingsâ (CPT A1) has the query which points to the CPT ârecipesâ (CPT A2) and its ACF Bidi Relationship field âfrom_the_cookingsâ (R2).
So when I look at a cooking event (CPT A1), I see all cooking recipes (CPT A2) that were linked to this specific cooking event via the ACF Relationship field (R2) .
I hope my case makes things clearer.
Cheers
Patric
That is incredibly helpful! Thank you!
I think it is very cool what you are doing with your gaming site and therefore I really want you to succeed with the relationship query!
Wow, you are incredibly kind! Thank you for all your help! I think I have reached a roadblock, with there seemingly a bug in bricks with loops, and if there is any relationships or adjustments to the query, the loading more or pagination does not work as expected. I managed to find a solution that works, but the pagination is proving to be a problem (it only loads the posts per page, with no way to load more on scroll). Waiting to hear if the dev team finds a fix.
Thank you so much for all your help, it is so amazing to see the bricks community so supportive!
Does this solution work if the bi-directional field is accepting multiple values? For some reason I cannot get it to work. Thanks!
Hi
My code is working for a â1 to manyâ relationship, meaning like in my case always only one (1) cooking event with many recipes.
I havenât tested it with many to many relationships. Technically it should work, because in the single post template there can only be one post id, but I am not sure.
Cheers
Patric