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:
- Best Practice for PHP
- Include WP_Query in my own PHP file?
- WordPress URL Rewrite not working
- Displaying a WooCommerce product via PHP
- Woocommerce -How to set product regular price default
- AJAX / Read More: multiple check_ajax_referer() and wp_create_nonce() not working independentely
- Display certain amount of posts on taxonomy archive page
- Thumb rating for wordpress – top user
- Result of Custom WP_Query appears on 404 Page (but result are found!)
- Show only one post for each author ( Page loads too slow )
- Bulk Image upload and one image for each post?
- how to display active, upcoming and past event with featured listing with pagination
- Get list of WP Updates Across Sites
- what is diference wp_get_attachment_url / wp_get_attachment_src / get_post_thumbnail_id?
- Modern Tribe Calendar wp-query with meta query not working at all
- WP_Query sort using multiple numeric meta values
- WooCommerce – Fixed quantity of a product [closed]
- WordPress WP_Query() Not working properly
- How to get to a specific position in wp_query?
- Get category name from custom loop and echo it once
- WP_Query loop, does not display special characters in title correctly
- Remove query string specific key value
- Hide post if matches current month and year
- Use WP_Query in shortcode
- How to create a custom category of wordpress admin
- Why is variable not working on custom sql query using wpdb?
- Accessing post’s meta data based on user’s click of a post
- Random order of WP_Query results with highest meta value
- Using foreach loop breaks
- Working with wordpress plugin and theme templates structures
- Dynamic content based on a URL parameter
- How to call WordPress function other files
- Get users that likes the post
- inserting a post from an extern php file but post content doesn’t show on wp site
- Woocommerce Show Single Product on Homepage
- Security for data obtained from the database
- WordPress add_rewrite_rules for custom URLs ending in .html
- How to get all author posts outside of author templates
- How to get post ID in a Page?
- How to retrieve the data from the sever and displaying it in a page?
- How to overwrite orderby with add_query_var
- Should i use the wordpress Options table or to create database table..?
- get_the_ID() in the footer returns wrong value
- change the default order of posts only for specific categories
- extract serialized array to use for wp-query
- WP_Query multiple post results
- echo var into wp_query
- Order a WP_Query by meta value where the value is an array
- Toolbar Hidden in a Virtual Page
- Woocommerce getting top level category parent and make all sub categories have the same template and menu
- Wp Query : Order by distance lat,lon
- Let current user know pending posts counts using wp_query
- get_terms with specific id order
- “pre_get_posts” orderby custom date field in different format?
- get different meta-data of a complicated query at the same time
- Using a new WP_Query inside the loop
- wp_query – Exclude the first thumbnail from lazy loading on archives
- WordPress sorting posts by date and title using a dropdown
- How to get specific multiple pages excerpts at homepage?
- Usermeta data unserialize, extract and display in table in WordPress
- How to get a specific string from a url
- Query on a repeater date (acf)
- Trying to get pagination working on WP_Query() post grid
- Check the database for a postmeta field
- Wp-query output correct, but the loop shows one less item (only sometimes)
- How to display sticky post always at the top (before regular post) in wordpress?
- Combine multiple queries, array_unique returns nothing
- Creating a WordPress addon for ContactForm7 submission (.XML file export)
- wordpress query returning unexpected results
- Custom Post type Ajax search results
- Display only upcoming events / Show all events when archive year is selected
- wp_query beginner
- Transfer WordPress Login Session to an Extended Webpage on the Same Domain
- How can I display a query in a page?
- direct query to post_meta table
- Add post class in custom loop (WP_QUERY)
- WooCommerce – Print Processing orders [closed]
- List sibling pages widget, exclude current page
- Why does WP_Query show only the same post even with different categories and endwhile?
- show/hide attachments
- WP_Query based on another query on the page
- Does wp_query and query_posts affect website performance? [duplicate]
- 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
- Show post like this image in my newssite [closed]
- Changing regular db connection to $wpdb
- what is %variable% in a wordpress plugin? [closed]
- Variable ++ in query loop
- XML WP_Query problem in PHP 8.0 and 8.1
- a problem in class in class-wp-hook.php
- Count custom posts type and filter by tag
- AJAX WP_Query’s order and orderby parameters not working
- 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
- Exclude first post from wp query
- AND and OR in my CPT search query depending on checkbox
- How can I save the HTML output of a WP_Query function as a variable?
- How do I use fields => ids in an array with WP Query?