Support » Fixing WordPress » Getting pagination to work and show up with this query

  • 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() ) {
                $test_items->the_post();
                $permalink = get_post_meta( get_the_ID(), 'test_item_permalink', true );
            }
            echo  paginate_links(); 
    
            wp_reset_postdata();
    
        } else {
            echo 'No feed items found';
        }

Viewing 6 replies - 1 through 6 (of 6 total)
  • 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>
        </div>

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

    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.

    Any other answers?

    HI,
    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 ….
    Regards

    Didn’t work either.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Getting pagination to work and show up with this query’ is closed to new replies.