Query block with meta keys based on acf fields

Hi there,

I am wondering if it is possible to Query using the query block using the meta argument based on an AcF field?

I can easily create a query by post type or specific taxonomies and mix these arguments.
Although if i add to it a meta based on acf fields then nothing works anymore, sometimes to the point it creates WP fatal errors (if i use a term query with meta instead of a post with meta) or just not display and even break the query block having to delete it and start over in order to get anything working…

Am I the only one?
If so can anyone show me the right way to do so?

Thank you in advance I feel like I spent a whole week on this without finding anything conclusive…

:pray::pray::pray:

1 Like

Here a little more details with one example to show the problem, I actually with this, I am going to move the topic to Bug.

This query works

<?php // The Arguments $args = array ( 'ignore_sticky_posts' => true, 'tax_query' => array ( 0 => array ( 'taxonomy' => 'artshow_type', 'terms' => array ( 0 => 41, ), 'include_children' => true, 'removeNoTerms' => false, ), ), 'orderby' => 'date', 'order' => 'DESC', ); // The Query $the_query = new WP_Query( $args );

If I add in the Query block modal
Meta Query
with Meta Key set to an ACF field country
with value as USA and string and compare set to ‘=’ (I also tried ‘LIKE’ with same result)
then nothing appears (even If I have matching records)
and the Query code becomes

<?php // The Arguments $args = array ( 'ignore_sticky_posts' => true, 'tax_query' => array ( 0 => array ( 'taxonomy' => 'artshow_type', 'terms' => array ( 0 => 41, ), 'include_children' => true, 'removeNoTerms' => false, ), ), 'meta_query' => array ( 0 => array ( 'key' => '', 'value' => 'USA', 'compare' => '=', ), ), 'orderby' => 'date', 'order' => 'DESC', ); // The Query $the_query = new WP_Query( $args );

As you see it seems like nothing is set to the meta_query key.

If I run as snippet with the current arguments but adding the key to the meta_query, then I see the results

Here the snippet {well the quote changed part of the code but you see my point)

function print_resume() {
$args = array (
‘ignore_sticky_posts’ => true,
‘tax_query’ =>
array (
0 =>
array (
‘taxonomy’ => ‘artshow_type’,
‘terms’ =>
array (
0 => 41,
),
‘include_children’ => true,
‘removeNoTerms’ => false,
),
),
‘meta_query’ =>
array (
0 =>
array (
‘key’ => ‘country’,
‘value’ => ‘USA’,
‘compare’ => ‘=’,
),
),
‘orderby’ => ‘date’,
‘order’ => ‘DESC’,
);
// The Query
$the_query = new WP_Query( $args );

if( $the_query->have_posts() ):
while ( $the_query->have_posts() ) : $the_query->the_post();

$the_link=get_the_permalink();
$the_title=get_the_title();
$outpout.=‘’.$the_title.‘
’;
endwhile;

endif;

wp_reset_query();

return $outpout;
}

Hello @JuGa,

Could you possibly take screenshot of your Query Editor and Meta Query so that I can how you’ve set this up?

Thanks in advance.

Hi @Louis ,
sorry I didn’t change the topic,
this is the same misusage that the one with sorting via ACF Field.

The answer is the one you gave us here:

Changing the topic to General and this as the solution.

Thank you and sorry for the waste of time…

J

1 Like