0

我试图只显示标记为的帖子in-stock并按它们排序inventory_number(这​​是一个数字值,所以我正在使用meta_value_num)。下面的代码是选择in-stock项目,但不是按 . 排序帖子inventory_number。我究竟做错了什么?

$args = array(
    'numberposts' => -1, 
    'post_status'=>"publish",
    'post_type'=>"post",
    'category_name'=>"tape",
    'meta_query' => array(
            'relation' => 'AND',
            array(
                'key' => 'inventory_number',
                'orderby' => 'meta_value_num',
                'order' => 'asc'
            ),
            array(
                'key' => 'status',
                'value' => 'in-stock',
                'compare' => 'LIKE'
            )
        )
);
4

1 回答 1

1

对于自定义字段的排序依据,meta_key=keyname必须存在于查询中。另外,我认为您不希望在AND子句中按顺序排列。所以试试这个...

$args = array(
    'numberposts' => -1, 
    'post_status' => 'publish',
    'post_type' => 'post',
    'category_name' => 'tape',  
    'meta_query' => array(
        array(
            'key' => 'status',
            'value' => 'in-stock',
            'compare' => 'LIKE'
        )
    ),
    'meta_key' => 'inventory_number',
    'orderby' => 'meta_value_num',
    'order' => 'ASC'
);
于 2013-05-18T06:26:49.030 回答