How to use the_posts_navigation for wp_query and get_posts?

the_posts_navigation() is simply a wrapper function for get_the_posts_navigation() which issimply a wrapper function for paginate_links. The first two functions uses the the same exact parameters that is being used by paginate_links and actually passes it to the latter function as well

get_the_posts_navigation() and the_posts_navigation() is good new functions as it eliminates a lot of custom coding and it is more user friendly for new unexperienced users who would like numbered pagination links

The only flaw in this get_the_posts_navigation() is that the developers went and wrapped the paginate_links function in a conditional statement that states that if the main query ($wp_query) has less than 1 page, (remember, the first page is 0 and the second page is 2), don’t show the links. This is problematic for custom queries on page templates. Pages will always have just one page, so these functions does not work with custom queries

The only true workaround if you have to use the_posts_navigation(), is to make use of @ChipBennet answer in this post. I really don’t like nullifying the main query (quite hacky, in my opinion this is just like using query_posts) but I can’t see any other solution to make get_the_posts_navigation() to work with custom queries

Leave a Comment