Acf relationship query loop filter by a value of a custom taxonomy

Hello to all,

I would like to know how to filter a loop query by the value of a specific taxonomy. The query contains articles given by an acf relationship field. Taxonomy is custom called positioning and I want to filter it for bank value.
Under i will put the code iā€™m using in the query editor php.
Can someone help me?
Thank you so much!

the_posts = get_field('formato_rel', get_the_ID());
return [
 'post_type' => 'formato',  //e.g. faculty
 'posts_per_page' => -1,
 'meta_query'        => array(
    'relation' => 'AND',
     array(
                'taxonomy' => 'posizionamento',
      'field' => 'slug',
      'terms' => ['banco'],
      'operator' => 'IN',
        ),
    array(
         'field' => 'ID',
      'value'     => $the_posts,
             'operator' => 'IN',
        ),
       ),
];

Hi

just looking at the code, you forgot the dollar $ sign in the first line:

must be

$the_posts = get_field(ā€˜formato_relā€™, get_the_ID());

Try it and let us know, if it works.

Cheers

Patric

Still doesnā€™t work with this correction my friend. Doesnā€™t give me any result back and the block is empty.

Any further suggest? Thanks a lot

In the setting of your ACF field, what did you set as the return value?

You must set it to return an array.

Cheers

Patric

To test your code, enter an id of a post in your code and see if it shows it.

For example, if you have a post with ID 100 that should be shown:

return [
 'post_type' => 'formato',  //e.g. faculty
 'posts_per_page' => -1,
 'meta_query'        => array(
    'relation' => 'AND',
     array(
      'taxonomy' => 'posizionamento',
      'field' => 'slug',
      'terms' => ['banco'],
      'operator' => 'IN',
        ),
    array(
         'field' => 'ID',
      'value'     => '100',
             'operator' => 'IN',
        ),
       ),
];

This way you can check if your query editor code itself is working or not.

I have tried but no results.
I have an issue like you respond in this post.
iā€™m actually in single post template.

With your suggest only using an id of an existing post type ā€œformatoā€ doesnā€™t work.
I have also tried with make a query loop on formato CPT with meta query using the acf relationship field.
I have to use the bidirectional field of the post tamplate or the field used in formato CPT.
And i have to give me back id or the entire object.
Thanks for your help @Patric !!

Maybe this will help you:

Hi my friend.

I have tried with both methods but continue to give nothing back.
Can you tell me what iā€™m missing?
Thank you very much for your support i have appreciate it!