我正在尝试按类别ID排序我的WordPress查询,但想要静态设置顺序。
下面的是设置顺序的参数:
'orderby' => 'ID',
'order' => 'ASC',
是否可以静态设置'顺序'
像这样:'order' => '50,49,48,51',
我尝试过使用post_in属性,但仍未看到订单更新:
$args = array(
'post_type' => $custom_post_type,
"$taxonomy" => $taxonomy_term->slug,
'post_status' => 'publish',
'post_in' => array(5,47,48,49,46,50),
'orderby' => 'post_in',
'posts_per_page' => 9999
);
答案 0 :(得分:1)
function posts_orderby( $orderby ) {
global $wpdb;
$orderby = 'FIND_IN_SET(ID, "50,49,48,51")';
return $orderby;
}
add_filter('posts_orderby', 'posts_orderby');
阅读:Returning query results in predefined order http://www.undolog.com/2012/03/13/wordpress-get_posts-e-orderby/
答案 1 :(得分:1)