订单价格在高级自定义字段(ACF) Wordpress


Orderby price in Advanced Custom Field(ACF) Wordpress

我的问题是:

我在Wordpress管理页面的ACF中创建了名称为price的新列。在前端,我想显示按价格降序排序的产品列表。

这里是我的代码ACF在Admin WordPress显示列价格:

add_filter('manage_edit-cars_columns', 'colum_xedulich');
function colum_xedulich($columns) {
    $columns = array(
            'cb' => $columns['cb'],
            'title'=>$columns['title'],
            'price_car' => __('price',_NP_TEXT_DOMAIN),
            'date' => __('Date','_NP_TEXT_DOMAIN')
        );
        return $columns;
}
add_filter('manage_cars_posts_custom_column','listProduct',10,2);
function listProduct($columns,$post_id){
    switch ($columns){
         case 'price_car':
            echo  get_field('price_from')." VNĐ ";
         break;
    }
}

但在前端,我想在DESC中通过price订购,但不工作:我的前端代码:

$post_page = isset($_REQUEST['post_page']) ? (int)$_REQUEST['post_page'] : $_REQUEST['post_page'];
$posts_per_page = isset($_REQUEST['posts_per_page']) ? (int)$_REQUEST['posts_per_page'] : 6;
$post_page = $post_page < 1 ? 1 : $post_page;
$posts_per_page = $posts_per_page < 1 ? 1 : $posts_per_page;
$the_query = new WP_Query(array(
    'post_type' => 'cars',
    'posts_per_page' => $posts_per_page,
    'orderby' => 'price',
    'order' => 'DESC',
    'paged' => $post_page
));

在我的案例中有什么方法对产品的price进行排序吗?

Replace

$the_query = new WP_Query(array(
    'post_type' => 'cars',
    'posts_per_page' => $posts_per_page,
    'orderby' => 'price',
    'order' => 'DESC',
    'paged' => $post_page
));

$the_query = new WP_Query(array(
    'post_type' => 'cars',
    'posts_per_page' => $posts_per_page,
    'meta_key'      => 'price',
    'orderby' => 'meta_value_num',
    'order' => 'DESC',
    'paged' => $post_page
));

希望能解决你的问题。