How to make this pre_get_posts function order my archives by custom field value

by Pete   Last Updated February 13, 2018 14:08 PM

I'm trying to get my archives to orderby posts by their custom field value e.g. 2018-06-23 10:00

//order archive posts by date
function order_archive_asc($query) {
  if ($query->is_archive() && $query->is_main_query() ) {
    $query->set('order', 'DESC');
    $query->set('post_status', 'future,publish');   
    $query->set('meta_key', 'date_time');       
    $query->set('orderby', 'meta_value_num');

  }
}
add_action('pre_get_posts', 'order_archive_asc');


Related Questions



Add custom field to the archive page?

Updated July 03, 2017 09:08 AM


More than one Hierarchical Taxonomy and SEO

Updated May 06, 2017 16:08 PM

Archive sorted by date and custom field

Updated August 10, 2017 10:08 AM