Site icon Hip-Hop Website Design and Development

Sort posts by post views and consider meta key

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