There is no need to juggle $wp_query
object, store it in temp, etc. It is rarely good idea to directly mess with important global variables, unless you absolutely need to.
You can just create your own arbitrary variable and init it with new WP_query
$some_variable = new WP_Query($args);
and so on.
Also don’t forget to cleanup after with wp_reset_query()
.
Related Posts:
- Output product category link from WP_Query
- WP_Query – How to query all of post types categories
- get_terms with specific id order
- How to work Woocommerce pagination inside shortcode?
- Isn’t Returning Value While Using SELECT COUNT(*) FROM {$wpdb->prefix}
- WP_Query for woocommerce products with a pattern as a post_title
- Woo-commerce Update price as a Bulk from My offline software export
- “pre_get_posts” orderby custom date field in different format?
- wp_query with multiple arguments with AND
- WordPress Search Ajax + Isotope + InfiniteScroll
- How do I make these combination select filters work when only one dropdown is set? They work in WordPress 5.8.2 but don’t in 5.8.3
- Passing in MySQL prepare statement parameter separately throwing error
- Replace a single variable with add_filter
- Nested Queries of decreasing specificity
- get different meta-data of a complicated query at the same time
- how to display recent post by category on home page
- Wrong pagination results, page counter resets when navigating
- Is it possible to order posts using multiple meta queries, i.e. show posts from first meta query, then the second?
- Sending simple variable on single page to WP JSON
- How to exclude meta no index pages from wp_list_pages
- Using a new WP_Query inside the loop
- Trending Tags based on post views
- Weird Behaviour: Not all WordPress Posts appearing
- divide custom field values in div every two values
- List of child pages fetch next results at link click
- Use custom get results query to show posts WordPress
- WordPress plugin creating sidebar on the theme/page
- List sibling pages widget, exclude current page
- Query category-specific, paginated posts and allow viewer to change sort order
- wordpress is_main_query() breaks
- WordPress and magic quotes
- Query seems to be duplicated
- Why does WP_Query show only the same post even with different categories and endwhile?
- allow previews outside wordpress folder (Outsourcing WP previews)
- How to get category pages to look like a certain archive page?
- How to get WordPress Adminmenu items?
- How To Customize Position of »add to cart« of WooCommerce on Product Page [closed]
- show/hide attachments
- Post Title Not showing up
- Advanced Taxonomy query, with 3 post types
- WP Query conflict on tag.php and category.php template
- Simple tree display of WordPress menu
- reorder a WP_Query, using a dropdown
- WordPress Pages into Sections edit.php PHP hack
- WordPress Plugin Receive a Link
- WordPress: Create A Widget to Accompany Plugin
- Custom query_posts() parameter
- WP_Query based on another query on the page
- Why does a meta_query break this WP_Query?
- Does wp_query and query_posts affect website performance? [duplicate]
- Keeping the previous get value and add another value when submitted
- WordPress post pagination on custom template not working
- Ajax Load More or View More functionality for woocommerce category layout by template overriding
- How can I list only Subcategories in Woocommerce
- PHP Syntax getting PHP terms
- Pagination in category.php not functioning
- How to modify this function to exclude also the post belonging to a specific category?
- Fix incorrect related posts code snippet
- wp_query on search results page showing all results every time
- Get Products within Current Product Category
- Show post like this image in my newssite [closed]
- Display biography post for today’s birthday person
- WP query with variables gives no result for specific user
- Display all categories (with link) of custom post type – WordPress
- Changing regular db connection to $wpdb
- what is %variable% in a wordpress plugin? [closed]
- How do I run the following script from my articles page?
- Variable ++ in query loop
- Execute multiple PHP Snippets causes error?
- XML WP_Query problem in PHP 8.0 and 8.1
- a problem in class in class-wp-hook.php
- How to initialise WP_Query on the basis of a specific meta_value and continue iterating rest?
- Count custom posts type and filter by tag
- Three different queries on same page
- How to sort custom sortable column by custom table value
- /page/2/ redirect to 404
- How to use a conditional statement in a post loop but not count towards the “posts_per_page” if false
- AJAX WP_Query’s order and orderby parameters not working
- Add adjacent post function inside custom recent post function
- How to sort search result by post_title, then by post_content
- How do I exclude the current post from the upcoming post query
- Accessing Correct Database to Create REST API Endpoint
- How do I display WooCommerce products in my query to rows of 3?
- How to get posts by a certain author in inner loop using outer loop variable or post title WordPress
- wp_logout action hook is not firing
- How to show correct td of table tags in wp_query loop
- Exclude first post from wp query
- Show post in elementor based on views and specific category with query id feature in elementor
- Check for a value in a custom query
- How to make posts_like_dislike reference current post when iterating?
- AND and OR in my CPT search query depending on checkbox
- Add css class ID to largest and smallest number a custom field in wp_query
- External WP_Query call from PHP crashed after version update
- How could I prevent using the same custom loop in a template file when I only need to change one meta_query parameter?
- Add up all numbers from a WordPress query [closed]
- Developing a “fallback” for empty wp_query results based on post dates
- Display posts in correct month order using single date custom field
- How can I save the HTML output of a WP_Query function as a variable?
- WordPress query_posts with multiple tax_query
- Elementor: Exclude product categories when using “Source: Current Query”