简体   繁体   中英

how to display popular posts by multiple meta keys in wordpress?

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM