Tipp: How to Meta Query for ACF Bi-Directional Query

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:

Rel1

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