[英]Display custom post type archive page as homepage
我拥有的代码在我的functions.php文件中,并根据需要显示自定义帖子类型“事件”帖子,但未按元值“ upcoming_date”进行排序。 它也不以升序排序。 此外,是否可以按2个元值排序? 请帮忙。
add_action("pre_get_posts", "cpt_front_page");
function cpt_front_page( $wp_query ){
//Ensure this filter isn't applied to the admin area
if(is_admin()) {
return;
}
if($wp_query->get('page_id') == get_option('page_on_front')):
$wp_query->set( 'post_type', 'events' );
$wp_query->set( 'page_id', '' ); //Empty
//Set properties that describe the page to reflect that
//we aren't really displaying a static page
$wp_query->is_page = 0;
$wp_query->is_singular = 0;
$wp_query->is_post_type_archive = 1;
$wp_query->is_archive = 1;
//sort the posts by meta value in ascending order
$wp_query->meta_key = 'upcoming_date'; // <= IS THIS RIGHT?
$wp_query->orderby = 'meta_value'; // <= IS THIS RIGHT?
$wp_query->order = 'ASC'; // <= IS THIS RIGHT?
endif;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.