WordPress自定义字段的排序依据

时间:2019-02-02 10:56:56

标签: php wordpress custom-fields

我正在尝试通过自定义字段InPrice进行订购,但无法执行此操作。我想知道是否可以通过其他方式('orderby' => 'meta_value_num', 'order' => 'ASC',)

$args = array(
    'post_type' => 'post',
    'posts_per_page'=>-1,
    'meta_key' => 'InPrice',
    'meta_value'   =>  array( $pieces[0], $pieces[1]),
    'meta_type'    => 'numeric',
    'meta_compare' => 'BETWEEN',
    'orderby' => 'meta_value_num',
    'order' => 'ASC',
    'meta_query'   => array(
        'relation' => 'AND',
            array(
                'btown' => array(    
                    'key'     => 'Town', 
                    'value'   => $town,
                    'type'     => 'STRING',
                    'compare' => 'LIKE', 
                ),
                broom' => array(
                    'key'     => 'Rooms', 
                    'value'   => $rooms,
                    'compare' => 'LIKE', 
                ),                                                                      
            ), 
       ),               
);

1 个答案:

答案 0 :(得分:1)

指的是Wordpress Documentation  您可以使用以下代码:

$args = array(
    'post_type'  => 'post',
    'posts_per_page'=>-1,
    'order'      => 'ASC',
    'meta_query' => array(
        array(
            'key'     => 'age',
            'value'   => array( array( $pieces[0], $pieces[1]) ),
            'compare' => 'IN',
        ), // other meta queries that you want 
    //don't forget to set a relation type for them in here ex:'relation'=>'AND',
    ),
);
$query = new WP_Query( $args );