You need to do a little “hack” to get pagination to work for your custom loop.
After you define $loop
, do the following:
<?php
// globalize $wp_query
global $wp_query;
// copy $wp_query into a temporary variable
$temp_wp_query = $wp_query;
// nullify $wp_query
$wp_query = null;
// move $loop into $wp_query
$wp_query = $loop;
?>
At this point, your posts_nav_link()
should work as expected.
Now, after the loop, swap the original object back into $wp_query
, so that everything else on the page that is query-dependent will work properly:
<?php
// restore original $wp_query
$wp_query = $temp_wp_query;
?>
Related Posts:
- How to make my pagination loop continuously?
- next_post_link for CPT only working for a few posts? weird!
- Why do next pages load the same content rather then older articles?
- Displaying the author of next and previous posts in pagination?
- Need help with get_posts pagination
- How to determine if I’m on the first page of pagination?
- How To create ajaxed wp-pagenavi?
- pagenavigation not showing the next page just linking back to the main page [closed]
- How do I insert CSS into a function?
- Pagination with $_POST and $_SESSION
- Next and Previous Posts of Same Parent
- Wp-pagenavi giving page not found on clicking page 2
- How to exclude or filter password protected posts when using next_post_link() previous_post_link
- query_posts pagination will always show identical content
- WordPress post pagination continuous [duplicate]
- WP Page Navi. 404 error when using posts per page parameter [duplicate]
- Pagination Links Not Showing Up on single.php posts on iOS Devices
- WP_Query and pagination AGAIN?
- remove rel=next on category page (if
- Page navi for template page
- Can’t Add Pagination
- Why next_posts(); function does not work inside header.php?
- WordPress not showing pagination links
- previous_posts_link returns null when querying custom post type
- pagenavi shows a lot of pages calculated from all posts in the site with query_posts
- Need help getting this page nav working correctly [closed]
- Next / Previous Posts not working
- pagination/prev and next page links not showing
- Pagination with wp_pagenavi not working on custom page
- Can the Next/Prev Post links be ordered by menu order or by a meta key?
- Is it possible to paginate posts correctly that are random ordered?
- Changing pagination list class
- How to determine if theres a next page
- WordPress /page/2 404 pagination problem – what to do?
- Paged posts – how to use numbers and next/previous links?
- Why do you need an unlikely integer in paginating?
- How to display pagination links for WP_User_Query?
- is it possible to get next_post_link
- How to show a single post on the front page but have normal paging?
- How to add CSS Class to previous_post_link or get previous/next post link URL
- Get Previous & Next posts by Post ID
- Filter next_post_link() and previous_post_link() by meta_key?
- Pagination resolving to first page only
- how to get pagination link url?
- add_rewrite_rule – working fine but broken for pagination
- wp_pagenavi() with custom wp_query()?
- How can I add title attributes to next and previous post link functions?
- How to get the number of Pages in a single Post Pagination?
- Aggregate comments, with pagination
- post pagination names, not numbers
- How to fix pagination after rewriting url? ie. www.site.com/players/type/pro/page/3/
- How can I make wp-pagenavi work on a custom query built upon a form submission? [closed]
- Display “Page 3 of 5” for a paginated post
- How to get next and previous post links, alphabetically by title, across post types, in a shortcode
- get_adjacent_post alternative on a very large db
- Implementing a general Table of Content across single paginated post pages
- Paginate links with “ugly” and “pretty” permalinks?
- Pagination of RSS2 feed
- Strange paginate_links behavior. First page link is always whatever page I’m on, all other links are correct
- Custom WP_Comment_Query with pagination and orderby?
- How can I get next/ previous post links to order by a filter (by the last word of the title)?
- Pagination: How do I always show ‘previous’?
- next and previous post link ordered alphabetically
- Next/Previous Links in same category
- Thumbnail (featured image) of next and previous post is not being properly displayed!
- Single Page View for Paginated Posts
- How can I see all of a post’s comments on a single page as a reader, if pagination is enabled?
- How can I limit the length of the previous/next posts in my WordPress Theme?
- How to use next_post_link and previous_post_link on single posts in search results
- Using paginate_links() to generate “1, 2, 3 … 10, 20, 30, 40… 55” paginations
- Change class=”page-numbers” in pagination
- Next/Previous Posts Links: Alphabetically and from Same Category
- Check if on last page of paginated post using wp_link_pages
- How can I get next post id after current post id for custom post type
- Problem excluding category from get_next_post
- Varying the number of posts per page from the first one
- Why is previous_post_link and next_post_link working outside of the Loop?
- Using pagination with get_posts on page type
- List posts based on first letter of posts
- Pagination for sub-pages
- adding custom fields to next and previous post link
- Modifying WP_LIST_AUTHOR Functions to output all users in a grid (and Paginate)
- How to get post pagination like this
- How to paginate a list of tags
- Pagination Not Displaying on Custom Term Archive
- Non existing blog pages are not redirected to 404
- posts_per_page & pagination conflict
- How to implement pagination eg. newer – 3 – 4 – 5 – 6 – 7 – older
- How do I sort multiples pages?
- specify meta_key / meta_value condition for prev_post_link and next_post_link
- Problem: ( kriesi ) pagination doesn’t work in homepage [duplicate]
- Custom loop pagination issue ( pagination not showing up )
- WordPress pagination on custom script
- Combining WordPress pagination functions for archives and search results
- Pagination is not working wp_query custom fields values
- Broken pagination
- Passing custom args in paginate_links
- Using previous_post_link and next_post_link to wrap around post sequence
- Limit number of pages in pagination
- wordpress Static Page pagination