WordPress.org

Ready to get started?Download WordPress

Forums

Popular Post Page Template Query Post Pagination Problem (4 posts)

  1. mckaymultimedia
    Member
    Posted 1 year ago #

    I have created a popular post page template for a theme that is under development. I plan to sort the posts by popularity based on page views. I have the page view tracking setup in custom fields for the posts and I even have a query string that retrieves the most popular posts in order successfully. On the first actual popular posts page it displays as it should.

    The problem I am having is that when you click to view the next page of popular posts using the pagination, it displays the same popular posts from the first page. Example: page "domain.com/popular" shows the top five popular posts, page "domain.com/popular/page/2" shows the same top five popular posts as the first page, and so on. The query isn't recognizing the pagination.

    I am no PHP or database expert so I am at a loss for what is going wrong here. My last resort will be to limit the popular posts page to a set number of posts, removing pagination. Here is the query in place before the loop...

    <? query_posts('meta_key=post_views_count&orderby=meta_value_num&order=DESC&posts_per_page=5'); ?><?php if (have_posts()) : while (have_posts()) : the_post(); ?>

    Any help, suggestions, or insight from more knowledgeable coders would be greatly appreciated.

  2. mckaymultimedia
    Member
    Posted 1 year ago #

    Bumpsky.

  3. MaruscaGabriel
    Member
    Posted 5 months ago #

    Hello mckaymultimedia, I have the same problem. You found any solution?

    Thank you in advance.

  4. mckaymultimedia
    Member
    Posted 5 months ago #

    In fact I did. I ended up figuring out a working query string on my own. Here is what worked for me.

    <?php query_posts(array('posts_per_page' => 5, 'meta_key' => 'post_views_count', 'orderby' => 'meta_value_num', 'order' => 'DESC', 'ignore_sticky_posts' => 'true', 'paged' => ( get_query_var('paged') ? get_query_var('paged') : 1 ), )); ?>

Topic Closed

This topic has been closed to new replies.

About this Topic