• I’m using a WP_Query with a meta_query key to get results from a custom post type using the following code:

    $args = array(
        'post_type' => 'werknemers',
        'meta_query' => array(
    	'relation' => 'AND',
    	array (
    		'meta_key' => 'user',
    		'meta_value' => $_POST['user']
    	),
    	array (
    		'meta_key' => 'city',
    		'meta_value' => $_POST['city']
    	)
        )
    );
    
    $post = new WP_Query($args);
    var_dump($post->found_posts);

    This code works, and returns all posible results (INT of currently two results). The values entered through $_POST are incorrect so it should return zero (int) results.

    I can’t figure out what’s wrong with my code.
    The strange this is that when I’m using the following arguments it does return zero results (int)..

    $args = array(
    	'post_type' => 'werknemers',
    	'meta_key' => 'user',
    	'meta_value' => $_POST['user']
    );

    So I’ll guess the problem is somewhere in the relation or, but using the documentation I can’t figure out what’s wrong.. All the help is appreciated, thanks in forward!

The topic ‘WP_Query with meta_query return results where zero expected’ is closed to new replies.