global $wp_query;
$original_query = $wp_query;
$wp_query = null;
$wp_query = new WP_Query( $args );
if ( have_posts() ) :
while ( have_posts() ) : the_post();
the_title();
the_excerpt();
endwhile;
else:
echo 'no posts found';
endif;
$wp_query = null;
$wp_query = $original_query;
wp_reset_postdata();
http://codex.wordpress.org/Function_Reference/wp_reset_postdata
Related Posts:
- Some doubts about how the main query and the custom query works in this custom theme?
- Using a custom WP_Query with get_template_part loop
- Loop within a loop?
- Get array of posts from the current archive page loop
- WordPress Custom Query to show posts from last x years
- How to order posts tag by tag?
- Loop through all tags & output posts in alphabetical list
- Pagination with 5 posts per page
- In loop: posts have thumbnail AND other variables
- Add inline HTML to posts published within last 24hrs
- Move posts to top of WP_Query if in certain Taxonomy?
- Display different number of posts from one category on the different pages
- How to display 3 different loops in 3 columns on homepage
- Splitting the main query in multiple loops with query_posts and/or pre_get_posts?
- Can certain (site-crashing) limitations on WP_Query in shortcode be overcome?
- WP_Query to get posts in a specific category and post format
- Implementing an OR statement to wordpress wp_query
- Get List of all the Authors
- Can’t get drafts with WP_Query using post_status parameter
- WP_Query doesn’t get sticky post at the top, when used in a page template
- Prevent duplicate post from dynamic multiple loops
- if/else on custom query gives 200 OK when condition not met?
- Refine search results using WP_Query
- Multiple Loops Inside a Function
- How to show subcategories using loop?
- Sticky posts are not showing at the top of category posts
- Storing query variable and then using wp_reset_query
- Show Sticky Post at the top but do not show again in the loop?
- Can I set my WP_Query to be a Main Query?
- Group and list posts by custom taxonomy
- Show scheduled posts in main loop but not in WP_Query?
- Change query based on post type while staying in loop
- Get a list of posts with associated meta_value
- Out Of memory issue on post per page parameter
- $WP_Query: How to display excerpt on first post only
- Check if loop has any categories?
- WordPress query with items from more than one selfdefined taxonomy as `term` argument
- How to make search for posts using get method?
- How to get list of posts from permalinks?
- Change query from cat id to slug or name?
- Using Wp_Query without the loop?
- Custom WP_Query id
- get_template_part causes 500 error
- how to use pre_gets_posts to exclude one queried ID from homepage loop
- WP_Query – Adding “offset” posts to the end of the loop
- Conditional operator OR not working with custom fields
- Get posts that do not have the same tags as current
- wp_query is showing posts from other categories
- Should I reset $wp_query?
- Exclude a Woocommerce product from WP_Query
- WP_QUERY wrong ammount of posts
- How to add sort order to incremented and paginated category loop
- How does WP generate the default $query in WP_Query based on the URL?
- how to get category`s slug in WP_Query loop?
- Expecting statement error from php loop using ACF plugin
- How do I sort this custom list of sticky posts
- Query only displays one page_id
- Get posts with no tags?
- wp-query, pull children of parent page
- I am officially missing something about transient posts
- WP_Query orderby random do not repeat infinite scroll – one loop
- Advise on Templates for Custom Queries
- How do I get the content of a custom instance of WP_Query?
- Query WP Page for Buddypress Group Home [closed]
- How to separate two columns from one content on a page template?
- How can I have sticky posts while ALSO showing posts from a specific category using one WP_Query?
- ACF: How can I publish values of ACF fields in a loop while using wp_query?
- Show a message if there are no active posts in category
- Avoid removing duplicate posts
- Problem with my loops
- Regarding a custom loop and output HTML tags
- Repeat array inside array through while loop
- What’s causing an infinite loop?
- display the children of the post using the current page as the main parent
- Display 3 levels of categories on page
- Paging works correctly on local version, but not live?
- pages shortcode filtering by category
- Custom post type loop error: Trying to get property of non-object
- Meta Query if Values Don’t Exist
- Get post Number with local loop and template
- How to order posts, that have already been filtered by custom taxonomy, by their category names?
- How to add in WP_Query to every 3 posts displayed? [duplicate]
- Display three sequential posts on each page load, without repeating previous
- How to make a wordpress loop file that displays posts based on certain conditions
- Problems with WP_Query, Loop, a condition and Posts per Page
- Custom loop – Isolating post meta output depending on current query taxonomy terms
- Issue in If else condition [closed]
- Pagination not working with WP_QUERY
- Custom search (wp query by custom fields)
- How do I display posts with specific value in a custom field into my loop?
- Limit the number of posts from a specific category on index.php
- Order by multiple meta keys on wordpress
- wp_query pagination links producing 404
- Display First posts without the default featured image
- Pagination problem with multiple loops on the same page
- Query for page content, and query for posts on the same page?
- Can’t seem to get an else statement correct? [closed]
- Output ACF field dynamicaly within a taxonomy loop [closed]
- How do I split a large query with a semi-expensive function included into multiple smaller queries
- Pagination only showed when no category is set in wp_query