按 high int meta_key 阀门显示产品

Show products by high int meta_key valve

我试图通过高 int val(meta_key) 显示产品,但代码使用相同的 int 值并排添加帖子。

$args = array(
'posts_per_page' => $limit, 
'orderby'     => 'meta_value',
'meta_key' => 'wpb_post_views_count',
'order' => 'ASC',
'post_type' => 'products',
'post_status' => 'publish',
);

$query = new WP_Query( $args );

foreach ($query->posts as $key => $post) {
# code here
}

'orderby' => 'meta_value_num'

Note that a 'meta_key=keyname' must also be present in the query. Note also that the sorting will be alphabetical which is fine for strings (i.e. words), but can be unexpected for numbers (e.g. 1, 3, 34, 4, 56, 6, etc, rather than 1, 3, 4, 6, 34, 56 as you might naturally expect). Use 'meta_value_num' instead for numeric values. You may also specify 'meta_type' if you want to cast the meta value as a specific type. Possible values are 'NUMERIC', 'BINARY', 'CHAR', 'DATE', 'DATETIME', 'DECIMAL', 'SIGNED', 'TIME', 'UNSIGNED', same as in '$meta_query'. When using 'meta_type' you can also use meta_value_* accordingly. For example, when using DATETIME as 'meta_type' you can use 'meta_value_datetime' to define order structure.

尝试:

$args = array(
    'posts_per_page' => $limit, 
    'orderby' => 'meta_value_num',
    'meta_key' => 'wpb_post_views_count',
    'order' => 'ASC',
    'post_type' => 'products',
    'post_status' => 'publish',
);

更多信息:Orderby Parameters