As Tom said, that will never work, as the main query have already executed. The only way to achieve that is to alter the main query before it is executed.
There is a action hook for that, pre-get_posts
and this is the correct method to alter the main query.
Example:
function wpse_custom_ppp( $query ) {
if ( !is_admin() && $query->is_main_query() ) {
$query->set( 'posts_per_page', '1000' );
}
}
add_action( 'pre_get_posts', 'wpse_custom_ppp' );
You can use additional conditional tags to target specific pages
Related Posts:
- remove tags from the_content
- the_title() shows title of the first post instead of the page title?
- How to place comments_template(); outside the loop?
- Endless loop with wp_insert_post and wp_update_post
- How do I prevent one of two multiple loops from repeating on a second page?
- Hook into the loop via a plugin, and output something after every X post?
- What exactly defines a Main Loop and a Secondary Loop?
- Loop code is displaying pages but not actual posts
- How are both HTTP and HTTPS versions displaying?
- Ajax loop refresh on click
- How do you split multiple-column loop on category archive page?
- How to Loop within a Loop (Display Children and then Grandchildren)
- Run The Loop over array of post objects
- the_excerpt(), get_the_excerpt() and the_content() all killing “the Loop”
- Enable infinite scroll on single.php [closed]
- Is get_posts() more efficient than The Loop?
- loop through all posts memory error
- How to loop through ALL pages?
- Does get_template_part pull data once in a loop?
- Get titles of all posts with current tags except current post
- How to retrieve “sticky” post outside the “loop”?
- Creating a multi-taxonomy query, excluding the newest (read: highest ID) taxonomy term
- Show a different post every 3 days [duplicate]
- Targeting a Certain Post in Loop (CSS)
- Using get_the_excerpt() Before The Loop
- code suddenly appearing from my tempate second loop
- Display most viewed post from last 30 days is not working correctly
- What is the maximum number of posts a WordPress loop can work with?
- wp_query inside the_loop
- How to go about combining dropdowns / filter queries?
- Split loop to load WordPress gallery into Bootstrap modal and carousel
- woocommerce get_price_html not pulling in correct price
- How to fix pagination for custom loops?
- WordPress Rewriting the DOM?
- How to display posts by vote count and if no value continue with latest posts with no votes?
- Sort results by groups of numbers and letters
- Modified loop-single-forum.php to work inside of a sidebar Widget, not working on some site pages
- Basic multiple loops only displaying first loop
- Display post list with different styles
- Both a page loop and posts loop on the same page
- Loop for sticky posts
- WordPress Blog has an infinite redirect loop
- Stepping through a foreach loop – adding +1 to the end of it so next time it loops it starts on item 2
- Array ids post to function have_post
- How to create bootstrap grid loop?
- Is it possible to reverse the order of a list of posts pulled from a loop?
- Give each posts in a loop a number in sequence
- First article : single column; Other articles : 2 columns
- How can I access specific posts brought back by query_posts?
- Put multiple custom loops on same page
- Contact information footer
- custom post on homepage
- Multisite foreach loop returning only one result
- Loop is crazy – one row displays wrong count of posts [closed]
- I have broke my pagination, same posts on all pages (index.php)
- I need to display all post in onepage
- Filter existing hook using parameter and foreach loop
- Run “the loop” in a random order
- How to put a block of code between [shortcode][/shortcode] in do_shortcode()?
- current-user_can not working in loop
- Show terms in archive page
- How can I access a post’s feature image outside the loop?
- Multiple loops for plugin
- Loops for cat links not looping for wordpress site
- Sort posts according to a numeric value entered with ACF
- wp_get_attachment_url not fetching URL?
- get the value for ALT is we check to see if an actual ALT value is set, if not we use the caption and if no caption is set we use the title
- Undefined index: page in loop load ajax content
- Only Show Excerpt After First 3 Posts
- How to get all multi-select user meta values and add them to an array?
- How to insert content before pagination in loop?
- How to resolve a reload loop issue in the frontend when logged in to WordPress multi-site backend admin area
- Excerpt isn’t working or am I missing something?
- Can I temporarily disable global $post?
- Shortcode for pulling specific Post Title outside loop when ID is passed in
- Show a list of user posts in the user admin page
- Deeply Nested Menu Loop with Twig using Timber [closed]
- WordPress redundant posts based on meta field
- Get featured image outside the loop using foreach
- Infinite Loop after Genesis Theme Upgrade
- pre_get_posts main_query not displaying after applying tax_query filters
- WordPress loop only displays 5 articles max?
- setup_postdata in “loop-handling” php file called via $.ajax
- Secondary loop cuts off at 10 posts?
- get_template_part() to render single page Theme
- Showing related posts (custom post type) outside of the loop
- get all page templates
- Paged homepage – requirements?
- Least Number of Loops to Create Custom Homepage?
- The Loop for my theme with static front page is not working
- WordPress loop: Display if posts exist
- strange parse error when including a loop template within another template
- Previous Posts Link and Next Posts Link Show All The Same Articles?
- Posts Loops To Display Specific Posts Inside Page Template?
- Use callback function in AJAX pure javascript [closed]
- Showing ads after posts in home page
- Undefined variable: woocommerce_loop [closed]
- title not being printed within html tag [closed]
- Prevent duplicating specific column from database table
- Use Base-URL with Query-Loop