Pagination cannot be reliably implemented in template. It is resolved during load way before template it ever reached.
Unless you implement it from scratch (complete with rewrite) you need to be using pre_get_posts
or other related hook to modify main query. Look around the site, there are plenty answer on topic of here.
Related Posts:
- Changing pagination list class
- Paged posts – how to use numbers and next/previous links?
- Paginate links with “ugly” and “pretty” permalinks?
- Strange paginate_links behavior. First page link is always whatever page I’m on, all other links are correct
- Pagination Not Displaying on Custom Term Archive
- Combining WordPress pagination functions for archives and search results
- paginate_links() outputs extra empty pages on custom loop
- In pagination, change link for page 1 to homepage
- Last page in pagination does not match max_num_pages – the overall post count is less according to pagination
- Invalid previous pagination links generated from paginate_links()
- Using Ajax in the prev_posts_link and next_posts_link
- Limiting number of visible links displayed with wp_link_pages
- search with pagination not working as expected
- Pagination Not Working on `WP_Query` Archive Page
- Include a leading zero in pagination
- Pagination Links showing incorrect previous page number
- Custom admin page pagination permissions error
- Paginate Links – Mid Size Less Than 2
- Paginate_links only working on first page
- Pagination on WP_User_Query not updating current page
- Automatically adding a link to the next page link before ” tag in posts?
- How to add pagination to category templates
- How to Show Next-Previous Link Only
- Show number of pagination pages even when total under two
- Can’t Add Pagination
- Sidebar pagination posts not shown when sidebar is in single.php
- Broken pagination links on WP 4.9.10 blog pages
- How to add post page pagination to template part?
- 404 page not found on pagination in home page while navigating to next page
- The pagination is working on Local, not on LIVE. why?
- Paginate Links in Wp Query Shortcode
- Extra pagination pages being wrongly generated
- Google Indexed sub pages in wordpress pagination in post
- Paginate Links function: Page 1 doesn’t work
- Disable pagination on frontpage
- Paginating custom posts in categories yields a 404 error
- How can I get my pagination to recognize that it is on the first page?
- Default pagination in Home/Front page
- Pagination only working on index page not on a template page
- Pagination Broken on Loop using ACF
- Is it possible to paginate posts correctly that are random ordered?
- How to determine if I’m on the first page of pagination?
- How to determine if theres a next page
- WordPress /page/2 404 pagination problem – what to do?
- Why do you need an unlikely integer in paginating?
- How to display pagination links for WP_User_Query?
- 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
- Pagination resolving to first page only
- how to get pagination link url?
- add_rewrite_rule – working fine but broken for pagination
- paginate_links() don’t properly work in search.php?
- 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/
- Display “Page 3 of 5” for a paginated post
- Getting paginate_links() ‘end_size’ to display none
- Implementing a general Table of Content across single paginated post pages
- Pagination of RSS2 feed
- How to paginate attachments in a secondary query as gallery?
- Custom WP_Comment_Query with pagination and orderby?
- Pagination: How do I always show ‘previous’?
- Next/Previous Links in same category
- How To create ajaxed wp-pagenavi?
- 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?
- Using paginate_links() to generate “1, 2, 3 … 10, 20, 30, 40… 55” paginations
- Change class=”page-numbers” in pagination
- Check if on last page of paginated post using wp_link_pages
- Custom Search Page Pagination Not Working
- Varying the number of posts per page from the first one
- Using pagination with get_posts on page type
- List posts based on first letter of posts
- Pagination for sub-pages
- 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
- 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?
- Problem: ( kriesi ) pagination doesn’t work in homepage [duplicate]
- Custom loop pagination issue ( pagination not showing up )
- WordPress pagination on custom script
- Pagination is not working wp_query custom fields values
- Broken pagination
- Passing custom args in paginate_links
- Limit number of pages in pagination
- wordpress Static Page pagination
- Static front page with recent posts pagination
- How to ignore or disable nextpage tag?
- Paginated pages are showing correct content but pagination links are not
- Paginate tags page
- pagenavigation not showing the next page just linking back to the main page [closed]
- Category pagination shows same posts
- How to display next and prev pagination links with WP_User_Query?
- Custom taxonomy list and sortby letter pagination problem
- Paginate a list of users?
- Move pagination numbers above plug-ins