• To allow for easy filtering of Posts with a specific Custom Field defined I’ve added a ‘meta_query’ parameter to the query via the ‘pre_get_posts’ filter.

    $query->set( 'meta_query', array(
    	array(
    		'key' => '_keyresource',
    		'value' => 1,
    		'compare' => '==',
    		'type' => 'numeric'
    		)
    	)
    );

    Is there any way I can limit this additional parameter to the main Post loop only?

Viewing 1 replies (of 1 total)
  • One solution I have used to turn a filter on and off is to use a global variable.

    I set the global variable just before issuing the query that I want filtered and then clear it just after the query.

    I check for the global variable in the filter function and only filter if it is set.

Viewing 1 replies (of 1 total)
  • The topic ‘Using 'meta_query' to filter Posts’ is closed to new replies.