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
- Pagination resolving to first page only
- Pagination of RSS2 feed
- Modifying WP_LIST_AUTHOR Functions to output all users in a grid (and Paginate)
- Problem: ( kriesi ) pagination doesn’t work in homepage [duplicate]
- How to ignore or disable nextpage tag?
- Show content only on front page?
- Getting 404 on taxonomy page
- Why am I getting a 404 on anything past page 1 of my query?
- Getting pagination for second loop to work on single.php
- WordPress custom URLs for pagination pages
- Home page not obeying post per page setting on the first page only
- How to add pagination to a single post
- WordPress rewrite rules for pagination on search page
- Styling the_posts_pagination With Font Awesome
- Pagination on 2nd loop
- Why does pagination go to a blank page when navigating through home.php?
- Pagination with $_POST and $_SESSION
- wordpress is converting ?page=2 into /2
- Add pagination to my custom loop [duplicate]
- Pagination with WordPress default gallery?
- How do i improve my custom pagination?
- Post Pagination Customization (wp_link_pages) Editing Navigation
- Default pagination is broken when use ‘static page’ as ‘front page’
- Paginate results from data fetched through array
- make a pagination that show posts by date
- Adding pagination on template page wordpress
- Pagination on custom post type not working if permalinks set to rewrite url
- Theme Option not Working Inside a Function
- Cannot go back to the first paginated page using pagination links
- Remember form field values with page navigation
- How do you choose to display specific posts/pages by parent url
- Hide content after going to page 2 of archive, show content when back at first page
- Add pagination to this following template
- split wordpress loop into columns of categories and associated posts
- How Change URL in Pagination pagebreak no plugins wordpress?
- How is the Page Splitting implemented in the theme?
- Why the page number does not appear in splitting post?
- Use of rewind_posts() cause pagination to break
- Pagination not working in custom post type but perfectly in posts
- Custom pagination with URL parameters
- how to add pagination to a popular post custom page?
- Add pagination – syntax error when copy/pasting
- Remove “Page” from Category archive
- Problem with Paging 404
- Pagination not working past page 3 on archive page of category
- Using the_posts_pagination with offset adds extra empty page
- Search, pagination, the last pages leads to 404 page
- Pagination is not working in custom page template
- How to implement pagination eg. newer – 3 – 4 – 5 – 6 – 7 – older
- 404 Pagination issue for only one category
- WordPress Pagination Not Working After Transfer from Localhost
- Removing template part when not on homepage if / else
- Paginate template name
- Pagination not working for archive
- foreach pagination
- paged query leads to 404? [duplicate]
- Pagination links not working for custom taxonomy
- I want the “next” and “previous” buttons to appear in my custom navigation function
- How to make infinite scroll by dividing the content?
- Change Pagination Default to “/2/” Query String “?page=2”