In order not to interfere with main wp_query
I would recommend to use this hook, that I used on one of my websites.
//wp_query to buffer
$temp_query = clone $wp_query;
//Use main wp_query with attributes
$wp_query = new WP_Query( array( 'posts_per_page' => 10 ) );
if(have_posts()) : while(have_posts()) : the_post();
//your code with html and etc
endwhile; endif;
//Get back to main wp_query
$wp_query = clone $temp_query;
Related Posts:
- How to display Yoast SEO meta description in archive template for each post instead of the_excerpt()? [closed]
- How to get Author ID outside the loop
- remove tags from the_content
- the_title() shows title of the first post instead of the page title?
- Why do themes rely on “The Loop”?
- How do I prevent one of two multiple loops from repeating on a second page?
- 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?
- Access to Media Library
- Getting two wp_link_pages output
- post loop causes wp_users and wp_usermeta DB queries for each users
- 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)
- the_excerpt(), get_the_excerpt() and the_content() all killing “the Loop”
- Is get_posts() more efficient than The Loop?
- loop through all posts memory error
- Get titles of all posts with current tags except current post
- 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)
- Get post/page data outside the 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?
- How can I create a legend (Key) like the one in the footer on WordPress StackExchange
- It is possible to encounter horrible bugs if I place a main loop that uses `query_posts` right above the main bbPress loop?
- Missing image in gallery shortcode in custom feed
- Styling text and images in the_content()
- Including post thumbnail url in loop’s post object to reduce number of queries
- How do I use AJAX Query in my posts loop?
- Duplicate posts in paginated results
- Output loop leveraged shortcode twice on one page
- Alter query using pre_get_posts() if meta_key is present
- Using Javascript for Looped Content
- Added if statement to loop
- How to get The Loop working with $wpdb->get_results()
- Making a query to the DB using same parameters of loop
- Variable not being passed into WordPress loop
- Pagination on Single Post
- Display Posts Only with Specific Tag
- How to get my loop to paginate?
- Group posts by date with a list
- Add class to last 3 posts in loop
- Get author Meta for particular user inside the loop
- Will only show the first 10 wordpress posts instead of all my posts
- WP Loop. If featured image is a panorama (3:1 ratio) execute some code
- Foreach displays from last to first
- value of metadata is null wrong use of if statement
- Count post views in loop
- displaying recent comments outside loop without plugin
- get_the_ID not returning correct ID value
- Include future posts in tags and in search
- Separate First Post Loop
- add offset to archive page
- loop inside the foreach
- Category ID returns as ‘0’?
- make get_post work in the loop
- How to display 3 post per slide
- 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
- For Each +1 WordPress Loop
- How can I access a post’s feature image outside the loop?
- Multiple loops for plugin
- Skip 5 latest post while paging?
- WordPress: query pages except remove one page
- get_post_meta printing empty fields, but it shouldn’t be
- Is it possible to set archive.php instead of index.php to display blog?
- How to read taxonomy in loop?
- Undefined index: page in loop load ajax content
- how to add 4 post in one carousel slide
- 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
- Is “the loop” a template tag?
- Excerpt isn’t working or am I missing something?
- Can I temporarily disable global $post?
- Deeply Nested Menu Loop with Twig using Timber [closed]
- WordPress redundant posts based on meta field
- WordPress with woocommerce custom query
- Get featured image outside the loop using foreach
- Infinite Loop after Genesis Theme Upgrade
- Page gets displayed in post field
- 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?
- Can’t see custom field after the Loop [closed]
- Same Loop on Multiple Pages
- get all page templates
- Paged homepage – requirements?
- 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]
- Undefined variable: woocommerce_loop [closed]
- title not being printed within html tag [closed]
- I make sticky post for my archive page for custom post type with ACF field and loop is not working