0

I want to display popular post in custom page , I have added post views and post like option in wordpress and I want to show popular posts based views and likes,

I tried this code but it's ranking only for views counter ;

$args = array(
  'posts_per_page'=>5,
    'orderby' => 'meta_value',
  'order' => 'DESC',
  'meta_query'      => array(
    'relation'    => 'AND',
    '_post_views' => array(
      'key'     => '_post_views',
      'type'    => 'NUMERIC',
      'compare' => 'LIKE'
    ),
    '_post_like_count'    => array(
      'key'     => '_post_like_count',
      'type'    => 'NUMERIC',
      'compare' => 'LIKE'
    ),
),
);

thanks for answers

1 Answer 1

0

Try new orderby feature:

$args = array(
    'posts_per_page'  => 5,
    'meta_query'      => array(
        'relation'    => 'AND',
        '_post_views' => array(
            'key'     => '_post_views',
            'type'    => 'NUMERIC',
            'compare' => 'LIKE'
        ),
        '_post_like_count' => array(
            'key'     => '_post_like_count',
            'type'    => 'NUMERIC',
            'compare' => 'LIKE'
        ),
    ),
    'orderby' => array(
        '_post_views' => 'DESC',
        '_post_like_count' => 'DESC'
    )
);
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.