Wordpress PHP-WP查询-按自定义字段排序

Wordpress PHP-WP查询-按自定义字段排序,php,wordpress,Php,Wordpress,我试图在我的帖子中按自定义字段排序,我有以下代码,它没有给出任何错误,但它类似于wp查询中的order by和meta参数不存在 if ($myURL[3] == 'recorded_lesson') { foreach (get_the_terms(get_the_ID(), 'rl_categories') as $cat) { $catID = $cat->term_id;

我试图在我的帖子中按自定义字段排序,我有以下代码,它没有给出任何错误,但它类似于wp查询中的order by和meta参数不存在

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 );

像这样更改代码并尝试

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 );

您是否对自定义字段使用ACF插件?不,我不是,自定义字段作为自定义元键存在于帖子中您是否对自定义字段使用ACF插件?不,我不是,自定义字段作为自定义元键存在于帖子中