I have a custom field called "value_date" where add a date e.g yyyy/mm/dd
The idea is sort the upcoming dates first in the loop, is possible?
I used a template for custom post taxonomy-event-date.php and this is code in the function, It doesn't work.
Functions.php
add_action('pre_get_posts','search_filter');
function search_filter($query){
if ( !is_admin() && $query->
is_tax( 'event', 'date' ) ) {
$today = date( 'Y-m-d' );
$query->set('post_status', 'publish');
$query->set('meta_value', $today);
$query->set('meta_key', 'value_date');
$query->set('orderby', 'meta_value_num');
$query->set('order', 'ASC');
}
}
pre_get_posts
questions, however- your date format is incorrect and will need to be changed to yyyy/mm/dd to sort correctly.