Support » Fixing WordPress » wp_query pagination trouble

  • Resolved Ghalt

    (@ghalt)


    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!!

Viewing 6 replies - 1 through 6 (of 6 total)
  • esmi

    (@esmi)

    Forum Moderator

    Try using $myPosts = query_posts($args);

    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

    esmi

    (@esmi)

    Forum Moderator

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

    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. 🙁

    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?

    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!

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘wp_query pagination trouble’ is closed to new replies.