My goal is to remove posts from my wordpress based home/category pages after they are no longer topical.
I have an 'expire_date' custom field for each post where I enter the date I want them to drop off.
Then (with help from Sally CJ), I use wp_query to filter through the posts and filter out the expired posts:
$query_args['meta_query'] = array(
array( // clause/query 1
'key' => 'expire_date',
'value' => date("Y-m-d"),
'type' => 'DATE',
'compare' => '>=',
)
);
That works great for the posts that have an entry in the 'expire_date' field... however, many posts don't - and apparently they are being filtered out to. They are not included in the results.
So how do I include those posts that don't have an entry?
I read through the wp_query doc and tried this - but the results is that none of the posts are displayed -
$query_args['meta_query'] = array(
array( // clause/query 1
'key' => 'expire_date',
'value' => date("Y-m-d"),
'type' => 'DATE',
'compare' => '>=',
),
array(
'relation' => 'OR',
array(
'key' => 'expire_date',
'compare' => 'NOT EXISTS'
)
)
);
clearly I am in over my head :) Any help appreciated!
Chris
relation
should be in the same level as the two arrays/clauses in yourmeta_query
array, i.e.'meta_query' => array( 'relation' => 'OR', array( 'key' => 'expire_date', ... ), array( 'key' => 'expire_date', ... ) )
:)