Search code examples
wordpresssql-likeadvanced-custom-fields

WP_Query / ACF Custom Fields find more than the exact match


I want to make a query for country, male and females. But i don´t know why, the Query always does not recognize that i requested an exact search.

When i query for males it always also querying (fe)males.

$args_members = array(
    'numberposts'   => -1,
    'post_type'     => 'members',
    'meta_query'    => array(
    'relation'      => 'AND',
    array(
        'key'       => 'country',
        'value'     => $country_site->term_id,
        'compare'   => 'LIKE'
    ),
    array(
        'key'       => 'gender',
        'exact'     => true,
        'value'     => '"˙.$gender_query.˙"',
        'compare'   => 'LIKE'
    ),
    )
);

$the_query_members = new WP_Query( $args_members );

I also tried a couple of variations manually:

  • 'value' => $gender_query,
  • 'value' => '"male"',
  • 'value' => 'male',

Any Ideas?


Solution

  • Its because you query with compare 'LIKE'... and male LIKE female is true actually. Change 'compare' => 'LIKE' to 'compare' => '='