[英]Wordpress PHP - WP Query - Order by Custom Field
我正在尝试按我帖子中的自定义字段排序,我有以下代码,它没有给出任何错误,但它就像 wp 查询中的 order by 和元参数一样不存在。
if ($myURL[3] == 'recorded_lesson')
{
foreach (get_the_terms(get_the_ID(), 'rl_categories') as $cat) {
$catID = $cat->term_id;
}
$myTaxQuery = array(
'post_type' => 'recorded_lessons',
'tax_query' => array(
array(
'taxonomy' => 'rl_categories',
'field' => 'term_id',
'terms' => $catID
)
),
'meta_key' => 'rl_number',
'orderby' => 'meta_value_num',
'order' => 'ASC'
);
$query['tax_query'] = $myTaxQuery;
}
return $query;
}, 10, 2 );
请问我在这里做错了什么?
像这样更改代码并尝试
if ($myURL[3] == 'recorded_lesson')
{
foreach (get_the_terms(get_the_ID(), 'rl_categories') as $cat) {
$catID = $cat->term_id;
$args=array(
'posts_per_page' => -1,
'post_type' => 'recorded_lessons',
'meta_key' => 'rl_number',
'orderby' => 'meta_value_num',
'order' => 'ASC',
'tax_query' => array(
array(
'taxonomy' => 'rl_categories', //double check your taxonomy name in you dd
'field' => 'id',
'terms' => $catID,
),
),
);
}
$wp_query = new WP_Query( $args );
}
return $wp_query;
}, 10, 2 );
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.