Support » Fixing WordPress » Using 'meta_query' to filter Posts
4 years, 7 months ago
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(
'key' => '_keyresource',
'value' => 1,
'compare' => '==',
'type' => 'numeric'
Is there any way I can limit this additional parameter to the main Post loop only?
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.