WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] wp_query pagination trouble (7 posts)

  1. Ghalt
    Member
    Posted 2 years ago #

    I have a custom query:

    <?php
    $paged = get_query_var( 'page' ) ? get_query_var( 'page' ) : 1;
    $args=array(
        'category_name' => 'blog',
         'paged' => $paged
    );
    $myPosts = new WP_Query($args);
    ?>

    When I try to use posts_nav_link, previous_posts_link and next_posts_link, both within and after the loop. And yet it is never showing anything to click on for navigation.

    Thoughts?

    Thanks!!

  2. esmi
    Forum Moderator
    Posted 2 years ago #

    Try using $myPosts = query_posts($args);

  3. Ghalt
    Member
    Posted 2 years ago #

    Hmm. I tried that and the page bombed on the "while have_posts" line that starts the loop.

    Fatal error: Call to a member function have_posts() on a non-object

  4. esmi
    Forum Moderator
    Posted 2 years ago #

    Then you'll need to add a posts_per_page parameter to the $args array for WP_Query.

  5. Ghalt
    Member
    Posted 2 years ago #

    Thanks for the efforts!

    OK...I tried that, too, with no luck still.

    I have the global setting at 10 (from the Dashboard, Settings, Reading screen), and I have my argument set to 3. I know there are more than 3 posts in this particular category, but 3 show up, and no navigation links. :-(

  6. Ghalt
    Member
    Posted 2 years ago #

    I've tried varying the contents of my arguments, and each is clearly having an impact, yet no values being displayed either in the loop or out of it.

    Is anyone else having similar issues?

  7. Ghalt
    Member
    Posted 2 years ago #

    OK...I figured it out.

    I retried esmi's recommendation about using query_posts instead of wp_query.

    The error I had gotten was because I had modified the while-haveposts syntax. When I reverted it back to default, the query_posts worked.

    Hope that helps someone.

    Thanks!

Topic Closed

This topic has been closed to new replies.

About this Topic