I have a post with three meta-fields.
add_post_meta($my_post, 'times', $times);
And i would like to query this category and sort the posts by the meta field value of one of them. The args i use right now are:
$args=array(
'post_type' => 'post',
'category_name' => 'players',
'order' => 'DESC',
'orderby' => 'meta_value_num',
'meta_key' => 'times',
'meta_query' => array(
array(
'key' => 'times',
'value' => 0,
'compare' => '>=',
),
'posts_per_page'=> '8'
)
);
Where times is the name of the metafield.The above code isn't returning anything.
You have 'posts_per_page'=> '8' inside your meta_query argument.
Change your code into the following:
$args=array(
'post_type' => 'post',
'category_name' => 'players',
'order' => 'DESC',
'orderby' => 'meta_value_num',
'meta_key' => 'times',
'meta_query' => array(
array(
'key' => 'times',
'value' => 0,
'compare' => '>=',
)
),
'posts_per_page'=> '8'
);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With