I’ve seen similar questions and solutions, but so far I couldn’t apply it to my code.
The following code (functions.php) works perfectly fine:
if( isset($query->query_vars['post_type']) && $query->query_vars['post_type'] == 'turniere' )
{
$query->set('orderby', 'meta_value_num');
$query->set('meta_key', 'date_start');
$query->set('order', 'ASC');
}
Now I want to add a sort of date range. This is the “best” I’ve got so far:
if( isset($query->query_vars['post_type']) && $query->query_vars['post_type'] == 'turniere' )
{
$query->set('orderby', 'meta_value_num');
$query->set('meta_key', 'date_start');
$query->set('order', 'ASC');
$query->set('meta_value', '20140520');
$query->set('compare', '>=');
$query->set('type', 'NUMERIC');
}
But it doesn’t work, the page just says “no posts available”.
I’ve tried different combinations of each parameter (meta_value with or without ‘, different compare methods and every possible type).
‘date_start’ is stored as yyyymmdd. I use the plugin “advanced custom fields” to set the date in each post.
Any help is much appreciated. 🙂