• Resolved ixwa

    (@ixwa)


    I’m using the value of a form post var in this meta_query but the result page is returning every post in the category, seemingly ignoring the key/value:

    $args = array(
    		'category_name' => 'dealers',
    		'meta_query' => array(
    			array(
    				'key' => 'state',
    				'value' => '"' . $locationData . '"'
    			)
    		),
    		'orderby' => 'title',
    		'order' => 'ASC',
    		'posts_per_page' => '-1'
    	);
    
    	$the_query = new WP_Query( $args );
    
    	//Show posts
    	if ( have_posts() ) while ( have_posts() ) : the_post(); ?>
    	blah blah etc.

    Also, it’s ignoring the -1 for posts_per_page (which should attempt display all matching posts).

    Have I made a glaring error or is there an issue with this syntax?

    Thanks.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Moderator keesiemeijer

    (@keesiemeijer)

    try with this

    $args = array(
    		'category_name' => 'dealers',
    		'meta_query' => array(
    			array(
    				'key' => 'state',
    				'value' => $locationData
    			)
    		),
    		'orderby' => 'title',
    		'order' => 'ASC',
    		'posts_per_page' => '-1'
    	);
    
    	$the_query = new WP_Query( $args );
    
    	//Show posts
    	if ( $the_query->have_posts() ) while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
    	blah blah etc.

    Thread Starter ixwa

    (@ixwa)

    Ah, so simple. I have to be careful where I copy code from…

    Works great–gold star for you!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Unexpected meta_query results’ is closed to new replies.