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 use more than 256MB of memory in the admin?
- When using the block.getSaveElement hook can you output different markup based on whether or not you are in the edit view or the live page view?
- WordPress audio player has two different styles
- Set user loggin status?
- Intercept invalid email during lost_password
- Only append custom classes to nav menu items
- redirect product-category to a custom page
- WP-Admin gives 403 Forbidden after login on CentOS 7
- Any tools for quickly grabbing comments / comment count?
- Custom WP_Query with no posts to output
- Adding Page Attributes and Page Templates to Custom Post Type WP 4.7.3
- syntax highlighting for theme-editor.php?
- adding homework to a school’s website
- Prepopulating a specific page template with HTML/CSS
- Toggle custom fields?
- Create page template via functions.php?
- How to add span on WordPress Title for first and third word
- Problem with custom function from jQuery slider tutorial
- Problems with setting up a subdomain to serve images and scripts
- Change login cookie expiration time?
- Disable “-mp4-image” screenshots from appearing in Media?
- WP Customizer – what types of fields is it capable of supporting?
- How to make my wordpress site responds for 2 domains
- How to answer, and we aren’t using WordPress to manage your site? [closed]