The Support Forums will be in read-only mode for a scheduled maintenance window on 01 September 2016 14:00 UTC - 20:00 UTC. More information.

Getting pagination to work and show up with this query (7 posts)

  1. drtanz
    Posted 4 years ago #

    I would like to paginate this query but I get no links for pagination at the end of the list of posts fetched. How can I fix it?

    $test_items = new WP_Query( array(
            'post_type' => 'test_feed_item',
            'posts_per_page' => $settings['feed_limit'],
            'orderby'  => 'meta_value',
            'meta_key' => 'test_item_date',
            'order' => 'DESC',
            'paged' => get_query_var('page') ? get_query_var('page') : 1,
        ) );
        if( $test_items->have_posts() ) {
            while ( $test_items->have_posts() ) {
                $permalink = get_post_meta( get_the_ID(), 'test_item_permalink', true );
            echo  paginate_links(); 
        } else {
            echo 'No feed items found';
  2. tiaanswart
    Posted 4 years ago #

    After you loop ends put the below code:

    <div class="pages">
            <span class="older"><?php next_posts_link('&laquo; Older Entries'); ?></span>
            <span class="newer"><?php previous_posts_link('Newer Entries &raquo;'); ?></span>
  3. drtanz
    Posted 4 years ago #

    That code is from a plugin, I did try using those two functions but they didn't output anything either. Any other ideas?

  4. drtanz
    Posted 4 years ago #

    For further information, this query is run via a shortcode, so it might be placed on another page or post. So it might be the case that the post is already paginated, but within that post we then find this code that is getting some posts from the custom post type, and they need to be paginated as well.

  5. drtanz
    Posted 4 years ago #

    Any other answers?

  6. jnhghy
    Posted 4 years ago #

    try with this:

    'paged' => get_query_var('page') ? get_query_var('paged') : 1,
        ) );

    instead of what you have now... + what tiaanswart suggested
    Hope this works ....

  7. drtanz
    Posted 4 years ago #

    Didn't work either.

Topic Closed

This topic has been closed to new replies.

About this Topic