0
我的代碼是在我的functions.php文件中,並根據需要顯示自定義帖子類型「events」帖子,但未按元值「coming_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;
}
看看這個:http://stackoverflow.com/questions/11100473/ordering-wordpress-posts-with-meta-values –
謝謝你的答案,如何將我的代碼中的實現?即:'$ wp_query-> order ='ASC';'不是這樣做的...... – karlosuccess