WordPress: query custom post type returns posts also if nothing equals to query

This is my query:

array(3) {
  ["post_type"]=>
  string(13) "sineverba_temp_reg"
  ["post_status"]=>
  string(7) "publish"
  ["meta_query"]=>
  array(2) {
    ["key"]=>
    string(27) "sineverba-temp-registration-card"
    ["value"]=>
    string(3) "123456789"
  }
}

$temp = new WP_Query( $args );

    if ( $temp->have_posts() ) {

           while ( $temp->have_posts() ) :

            $temp->the_post();
            $id_post = get_the_ID();

        endwhile;

    }

    //other stuff

That “123456789” does not exists in database, neither in the post meta. But the query returns ALL the custom post types that I have.

If I search for a value that exists, returns the only one that match.

How Can I return a null / nothing if my query doesnt’ find nothing?

Read more here: WordPress: query custom post type returns posts also if nothing equals to query

Leave a Reply

Your email address will not be published. Required fields are marked *