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:
- 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
- Catch 404 after changing permalink structure from /%postname%/ to /%category%/%postname%/
- What’s the URL for a category archive?
- Rewrite rule page url with category
- How to create a custom url for a category [closed]
- Exclude categories from search query
- 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
- How to Include the Parent and Child Category in the Permalink if the Post is Added to Both
- Custom Query to search through categories
- Pagination on child category returns 404
- How to show empty category in admin menus search
- Disable pagination only for specific category
- Archive pagination causing 404 with permalinks structure
- How to select product category while adding new product in woocommerce? [closed]
- How do I get the total number of categories in a list of search results?
- Show posts of category in a page
- Filtering search results
- WooCommerce change category url and product base
- Help with multiple dropdown tags search
- Using a portfolio_category slug in wordpress URL
- Viewing category pages without the word ‘category’ in URL
- Pagination Not Working on Category.php page
- Multiple Category Search
- get_the_category and echo out link to child-most/deepest category
- Broken category pagination
- ?cat=-1 Indexed Versions Of Homepage
- Add “page-a” slug to category link if user visit category link from “page-a”
- How to query post like normal search would do. within search.php page
- Pagination for category slug returns 404 when page >= 2
- Rewrite a category
- WordPress search only showing a few posts
- Pagination is not working properly in Product Category/Tag pages
- Select posts by name and category per REST API
- Paging not working in category.php
- Custom post and category template pagination problem
- Custom category URL rewriting
- category url structure
- Category template with pagination returns 404 on next pages
- How to conditionally hide author name on Single.php if category is “news”, otherwise if category is something else display author name?
- Conditional IF current cat is the smallest/last/end child cat THEN
- How to display numbered pages in a category
- How do I display something on a particular category page?
- Exclude a category from a query that includes its parent category
- WordPress alphabetical A-Z custom post type post result display
- How to show 1-5 of X Total Results
- Hierarchical permalink structure for posts showing categories and sub-categories
- Get URL Category Name By ID
- Nicer URL for viewing category of posts?
- Problems with my conditionals in single.php by category
- Change of category structure will cause two kinds of URLs for one post
- Group search results by category
- Woocommerce search form with category select
- Home Page Template – Specific Category
- 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?
- Global navigation in multisite: problem with categories
- How do I remove pagination from just some Categories?
- 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
- Return all Tags and Categories in Separate List
- How to remove category name for only one category?
- Pagination for custom categories template
- Can a Woocommerce product category URL contain “&”?
- Category page 404s on mobile but not desktop?
- Category URL’s 404 after setting category base to ‘.’
- Unable to create pagination for Category.php
- Search Replace Database ONLY for posts of certain category?
- “Next posts” of a category do not call category.php
- Search by tag, category and author without plugin
- 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
- WordPress pagination not working because of subcategory
- Catch 404 after changing permalink structure from /%postname%/ to /%category%/%postname%/
- A search box for all sites – Multisite
- Paginations in Category Page Leads to Sample Pages
- Conditional statements based on custom meta value in category archives
- Modify / Rewrite single template url structure
- Paginating a list of all posts collected by category titles
- Paginate WordPress Category Pages
- Using pagination with multiple loops causes it to break
- How can I get rid of the the category suffix–NOT “prefix” (i.e. foo-1, foo-2, etc)
- Query posts that have all the specified tags
- Multiple Parent Category URLs
- Why Pagination is not working on Category.php
- Display category tree of a post in search results
- Category pagination not working in category.php please help me
- Link to page in category
- Remove “All categories” from searchbar dropdown
- wordpress category rewrite rule with pagination