1
votes

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.

1

1 Answers

1
votes

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'
);