Need Help with Views Popular Posts

Support MB Views Need Help with Views Popular Posts

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #39123
    JamesJames
    Participant

    I want to show most popular post using views, but I am having a problem with twig templating. Can you help me guys?

    $popularpost  = new WP_Query(array(
        'posts_per_page' => 5,
        'meta_key' => 'wpb_post_views_count',
        'orderby' => 'meta_value_num',
        'order' => 'DESC'
    ));

    I tried to copy, here's my query but doesn't show any post

    {% set args = { post_type: "post", posts_per_page: 4, meta_key: "wpb_post_views_count", orderby: "meta_value_num", order: "DESC" } %}
    {% set posts = mb.get_posts( args ) %}
    
    {% endfor %}
    #39132
    PeterPeter
    Moderator

    Hello,

    If you run the query with the PHP code, does it show posts properly?

    $popularpost  = new WP_Query(array(
        'posts_per_page' => 5,
        'meta_key' => 'wpb_post_views_count',
        'orderby' => 'meta_value_num',
        'order' => 'DESC'
    ));

    If yes, it should work in Twig code.

Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.