• Can someone post an example of a query that has a meta_query for a custom select field with multiple values? Here’s my attempt, which doesn’t work…

    $args = array(
    	'posts_per_page' => 3,
    	'meta_query' => array(
    		array(
    			'key' => 'myfieldname',
    			'value' => array('myvalue'),
    			'compare' => 'IN',
    		),
    	),
    );
    $query = new WP_Query($args);
    var_dump($query->have_posts()); // Returns false :(

    Thanks

Viewing 1 replies (of 1 total)
  • Thread Starter webcomm

    (@webcomm)

    Here’s the solution, which I find quite strange:

    $args = array(
    	'posts_per_page' => 3,
    	'meta_query' => array(
    		'relation' => 'OR',
    		array(
    			'key' => 'myfieldname',
    			'value' => 'myvalue',
    			'compare' => 'LIKE',
    		),
    	),
    );
    $query = new WP_Query($args);
    var_dump($query->have_posts());

    Surprisingly unintuitive that “LIKE” would be used here. One would definitely not use a LIKE query if coding something like this from scratch with PHP/MySQL.

Viewing 1 replies (of 1 total)
  • The topic ‘wp_query for select field with multiple values?’ is closed to new replies.