WordPress.org

Ready to get started?Download WordPress

Forums

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

  1. drtanz
    Member
    Posted 1 year 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() ) {
                $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';
        }
  2. tiaanswart
    Member
    Posted 1 year 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>
        </div>
  3. drtanz
    Member
    Posted 1 year 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
    Member
    Posted 1 year 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
    Member
    Posted 1 year ago #

    Any other answers?

  6. jnhghy
    Member
    Posted 1 year ago #

    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

  7. drtanz
    Member
    Posted 1 year ago #

    Didn't work either.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags