Home Forums Front-end Issues Better query for ACF checkbox values? Reply To: Better query for ACF checkbox values?

  • Hi @avwijk

    I believe you can use the IN compare instead. You should also always try to use the WP_Query class instead of get_posts(). That’s just a wrapper which also bypasses several filters.

    There’s also a few performance tricks one can do to improve performance on the WP_Query class. a single WP_Query actually runs 4 queries per default. We can disable some of these. Below is your query with two of the four queries removed.

    $posts = new WP_Query(array(
    	'post_type'			=> 'team_member',
    	'posts_per_page'	=> 500, //never set to -1 as this is an hazard. what if we at some point has 10 000 posts? 
    	'no_found_rows' => true, //since we dont use pagination we can use this
    	'update_post_term_cache' => false, //Since we dont use taxonomies we can use this. If you are going to output taxonomies based on this query remove this line.
    	'meta_query' => array(
    		'relation' => 'OR',
    			'key' => 'groep', 
    			'value' => array('7a', '7b', '8a', '8b'),
    			'compare' => 'IN'