Sort posts by post views and consider meta key

Question

my code should show popular posts where the meta key “slider” isn’t empty. Have anyone an idea why it doesn’t work?

The problem is that this code only shows posts with a slider image. But it ignores the sorting.

$values = array(
  'numberposts' => 10,
  'orderby' => 'meta_value_num',
  'meta_key' => 'count_views',
  'meta_query' => array(
      array(
        'key'     => 'slider',
        'compare' => '!=',
        'value'   => ''
      )
  )
);

$my_posts = get_posts( $values );
global $post;
foreach( $my_posts as $post ) : setup_postdata($post);

   the_title();

endforeach;
wp_reset_postdata();
0
Nepo Znat 7 years 2014-03-24T09:31:24-05:00 0 Answers 59 views 0

Leave an answer