I think it should work by hooking into pre_get_posts
:
function wpse_254661_remove_pagination( $query ) {
if ( $query->is_main_query() && get_query_var( 'onepageprint', 0 ) ) {
$query->query_vars['nopaging'] = 1;
$query->query_vars['posts_per_page'] = -1;
}
}
add_action( 'pre_get_posts', 'wpse_254661_remove_pagination' );
Like this you can modify your query right before it gets fetched and the query object gets passed by the hook right into the function. There is also a check to only affect the main query.
Related Posts:
- Display posts from the same category using next/previous post link
- How can I create a category landing page followed by pages of posts?
- Posts URL structure like site.com/category/the-post-title
- How to get permalinks with category base working with sub-categories
- How to remove the term “category” from category pagination?
- Catch 404 after changing permalink structure from /%postname%/ to /%category%/%postname%/
- WordPress Multiple Category Search
- What’s the URL for a category archive?
- Rewrite rule page url with category
- Multiple post categories – single permalink
- How to create a custom url for a category [closed]
- Display all posts from all categories with pagination
- Exclude categories from search query
- Add forward slash on categories url (serve one version of a url)
- How to search for categories and/or tags?
- Using URL parameters, list posts from category and custom taxonomy
- Sticky posts on home page, search, tag and archives without plugin
- Show Previous/Next Posts navigation only inside the same category
- Create product category and keyword search form in woocommerce? [closed]
- Rewrite category wordpress
- How to create non-unique sub-category slugs?
- How to Include the Parent and Child Category in the Permalink if the Post is Added to Both
- Exclude subcategories from the url
- Pagination doesn’t work on multiple categories
- Search form options group categories
- Pagination breaks on child-categories, works fine on parent-category
- Pagination for a category
- Can I define multiple paginations on a single page?
- Conditional category query breaking?
- Category pagination not working
- Global navigation in multisite: problem with categories
- How do I remove pagination from just some Categories?
- Include specific category in URL automatically
- WooCommerce Product category can be shown with multiple related URLs
- Show Posts via cat+cat in URL that are in both Categories doesn’t work
- Problem with pagination block in Gutenberg
- WordPress Default Category and Custom Taxonomy Selected Attribute not Working After Searched in wp_dropdown_categories Array
- Show the number of the post
- Automatically adding tags and categories into Post Excerpt for searching
- pagination 404 error, same slug home and categories
- A different permalink structure for different categories
- Return all Tags and Categories in Separate List
- How to remove category name for only one category?
- Is this process OK to replace URL structure?
- Pagination for custom categories template
- Can a Woocommerce product category URL contain “&”?
- Remove WP Core canonical for category pagination
- Category page 404s on mobile but not desktop?
- Category URL’s 404 after setting category base to ‘.’
- Unable to create pagination for Category.php
- Change the full slug for a specific category?
- Search Replace Database ONLY for posts of certain category?
- Pagination does not work with query_posts()
- “Next posts” of a category do not call category.php
- Search by tag, category and author without plugin
- WordPress pagination based on category
- Issue with WordPress category search
- How to add Pagination to foreach loop to page
- get_terms sort order with child categories of varying depth
- Conditional statement: if is_category, append at the end of page
- Accessible Subcategory URL’s pages without using .php hack
- Removin /page/2 from pagination
- WordPress pagination not working because of subcategory
- 404 error when i try to search by category or by tag
- Catch 404 after changing permalink structure from /%postname%/ to /%category%/%postname%/
- Make related posts display first in search result
- A search box for all sites – Multisite
- Loop within category’s posts
- Paginations in Category Page Leads to Sample Pages
- Category foreach Paging
- Transfering static site to wordpress and retaining category by month paginations
- Conditional statements based on custom meta value in category archives
- WordPress Numeric Pagination with Query String [duplicate]
- date.php shows all posts. how to fix it?
- Modify / Rewrite single template url structure
- Several loop in search result
- wordpress category.php query for featured news item, broken pagination and repeating posts
- Paginating a list of all posts collected by category titles
- Paginate WordPress Category Pages
- Using pagination with multiple loops causes it to break
- Search functionality with multiple categories
- How can I get rid of the the category suffix–NOT “prefix” (i.e. foo-1, foo-2, etc)
- Showing one post from each category, paged?
- Query posts that have all the specified tags
- Multiple Parent Category URLs
- Why Pagination is not working on Category.php
- Can i know if it is Category first page or 5th?
- Exclude posts from certain category breaks custom pagination
- Display category tree of a post in search results
- Category pagination not working in category.php please help me
- i want to add pagination list of categories
- Link to page in category
- How can I implement pagination on custom category page?
- Weird html output of single_cat_title – is not inside of the html element?
- Remove “All categories” from searchbar dropdown
- wordpress category rewrite rule with pagination
- Display different sidebar based on search results from one category
- Link from page to category posts
- Link to a specifc category?
- Category page 2 url doesn’t exist