WordPress通过调整query


Updated on: August 9, 2020 in Office by

通过function来调整:

add_action( 'pre_get_posts', 'university_adjust_queries' );

function university_adjust_queries($query) {

 if (is_post_type_archive('event') && !is_admin() && $query->is_main_query()) {
   $query->set('meta_key','event_time');
   $query->set('order_by','meta_value_num');
   $query->set('posts_per_page', '-1');
    $query->set('meta_query',array(
      array(
       'key' => 'event_time',
       'compare' => '>=',
       'value' => date('Ymd'),
       'type' => 'numeric'
      )
     )
    );


 }
}