我有一个自定义的帖子类型即投资组合,我需要能够通过作为作者名称的元值对其进行排序:::我已经尝试了几个例子但没有工作:::任何帮助将不胜感激: ::
我的代码
$args = array(
"post_type" => "portfolio",
"meta_key" => "authors_name",
"orderby" => "meta_value",
"order" => "ASC"
);
$custom_query = new WP_Query( $args );
这也不起作用
$args = array(
"post_type" => "portfolio",
"meta_key" => "authors_name",
'meta_query' => array(
array(
'key' => 'authors_name',
),
),
'orderby' => 'meta_value',
'order' => 'ASC',
);
答案 0 :(得分:4)
我能用add_filter('pre_get_posts':::)对这个问题进行排序实际上这就是我的脚本现在的样子:::
function laudes_order( $wp_query ) {
$wp_query->set('meta_key', 'authors_name');
$wp_query->set('orderby', 'meta_value');
$wp_query->set('order', 'DESC');
}
add_filter('pre_get_posts', 'laudes_order');
$args = array(
"post_type" => "portfolio",
);
$custom_query = new WP_Query( $args );