The best way to do this is to use the pre_get_posts filter, which changes the main query. That way you’re not running the default query plus a custom one on top of it. You’ll have to determine the “if” conditions to only run on the query you want to affect:
<?php
function wpse_366882_get_all_posts($query) {
// This will run for all main queries that are not in wp-admin.
// You may want "is_archive()", "is_page('slug')" or some other condition.
if ( ! is_admin() && $query->is_main_query() ) {
// Setting to -1 shows all.
$query->set( 'posts_per_page', -1 );
}
}
add_action( 'pre_get_posts', 'wpse_366882_get_all_posts' );
?>
You can place this code in a custom plugin, or in a custom theme or child theme’s functions.php file.
Related Posts:
- WordPress Paginate $wpdb->get_results
- How to add a new product type on woocommerce product types? [closed]
- Updating WordPress overwriting customization tweaks – strategies?
- How to customize the default HTML for WordPress Attachments
- wp_trim_words() does not trim the_content() in WordPress
- pagination in woocommerce order history page
- page_template toggle between 2 templates + 2 permalinks for same post
- Make page template that is just an “include” of another?
- Custom php file in wordpress
- Selecting An image from the Media LIbrary on the frontend
- WordPress Template not affecting the working, keeps defaulting to the index.php template
- Recommend an open source, template driven website builder UI that produces a working WordPress site [closed]
- Adding Pagination on a Custom Author Page
- For custom templates, is it better to use `template_include` or `type_template`?
- Create default_content layout template based on post id
- Remove template drop down for certain pages
- How do I add a new template to my site
- Paginate Author’s Post List on Custom Author Page (ANOTHER THEORY)
- How to customize core admin pages within a theme?
- How can I make site-wide content editable, for example footer content
- Query post for ‘selected category’ in archive.php
- Pagination Issues using WP_Paginate Plugin
- Showcase elementor templates
- How to get custom page template being edited in gutenberg editor
- Make custom page look exactly as homepage
- Best practice – pages – ACF or inline coding
- Set Title from Custom Template
- How to hook up search results page to a back-end page?
- How To Load an HTML File As A WordPress Page (With No 301/No Redirect)
- Hide text if not homepage
- website with pretty permalinks except pagination
- Editing a post template
- WordPress archive index page
- Need help with pagination
- How to custom post navigation
- How to add custom ‘layout’ buttons to wordpress editor?
- How to create custom layouts and static pages in themes for clients
- Custom Content Page
- Pagination with custom field
- Create a Page template selector page
- Creating custom page template
- Force WordPress to load a specific template
- Dynamic Sidebars based on page name
- Translate custom template with WPML
- How To make Custom page of every Category
- WordPress pagination with custom post type?
- why won’t my custom css load with the enqueue method or any other method?
- Conflict between Yoast SEO and my custom theme
- How to add a template – so that i can choose a different menu for some pages
- Custom query pagination with php parameter as arg problem
- How can I delete the word `Category:` from page titles? [duplicate]
- How can I add category variable inside posts?
- Why does a custom php code inside a custom template not get executed?
- wordpress custom posts page not showing
- How do I target this page specifically?
- How to use a custom playlist template:
- Still desperate about multiple TinyMCEs in widgets – is there any good solution to this yet?
- Displaying Child Page’s Information
- Getting a jQuery library to work in WordPress & Avada
- Use another theme template in my theme
- Redirect Every Instance of The Author Template Pages to Custom Author Pages
- Allow arbitrary text after page URL
- Taxonomy template by post type
- WordPress custom search – pagination
- Best way to create a page outside of the pages list
- Template setting is not saving in wordpress
- Make Terms Under Custom Taxonomy Use Specific Single.php Template
- Custom single page based on which custom page template is selected
- Pagination is not working on custom query
- Single page template
- Adding css and js to a blank page created with custom template
- Modifying a local template
- Custom template not working for existing pages [closed]
- Gallery Pagination by Row
- How to apply styles to the custom page template
- Create a page for each database table entries
- How to edit the new user email notification template
- Custom Walker: how to get ID in function start_lvl
- How can I create an alternative home page?
- Customizer image control default value showing in customizer but not on frontend
- Change default status and replace the icon for an hamburger menu
- How to access my php page in wordpress
- Search result page redirect ex.com/?s=searchterms to ex.com/searchterms
- Add styles with wp_add_inline_style only if modifications exist wp_add_inline_style
- Add custom field to woocommerce variations [closed]
- need help with a user-specific custom page template
- Gravity Forms – gform_field_value – query custom table breaks functions.php
- Let author add field to metabox by pressing a button
- Create theme for mobile phones and tablets only?
- Usage of custom post types in a custom admin menu
- display text generated via custom get query string
- Custom post-type working except for Selecting page-parent
- How could I change contact details in the footer?
- Custom Route Returns 301/Passing Variable from Input
- Menu selection for header
- How to display custom admin pointers (tips/notifications) in Dashboard until dismissed?
- Expressions and str_replace
- How to create a new blog in wordpress?
- Pass the post ID
- Include plugin´s table in custom query