After you create your custom query, you just write The Loop as you would for the default query. So your code would look like this:
if ( $query->have_posts() : while ( $query->have_posts() ) : $query->the_post();
// Your Post Stuff Goes Here
endwhile;
wp_reset_postdata();
else :
// No Posts Found Code Goes Here
endif;
Note the use of wp_reset_postdata()
. This is mandatory for custom queries. This function resets the post data back to the default query as URL requests are based on the default query and will load before templates.
Related Posts:
- retrieve thumbnail from post ID of best selling product in category
- WP_Query | Help me create a search term with an ‘OR’ relation?
- Using Cookie Data For WP_Query Loop
- Display related products with custom output
- How can I use wp_query to show all product data using just the products ID?
- Display a specific category of products in shop page and disable code for specific actions
- inserting a post from an extern php file but post content doesn’t show on wp site
- get_total () returns 0 – woocommerce [closed]
- How to display SQL query that ran in WC_Order_Query?
- WP_Query multiple post results
- WordPress WP_Query without query GET parameters
- Output product category link from WP_Query
- How to work Woocommerce pagination inside shortcode?
- WP_Query for woocommerce products with a pattern as a post_title
- get_filtered_term_product_counts – Get product terms if any products
- WP_Query To Display Product Of Brand On Taxonomy Page
- Woocommerce Related Product by 2 taxonomy
- WooCommerce – Print Processing orders [closed]
- Ajax Load More or View More functionality for woocommerce category layout by template overriding
- Add Woocommerce Customers link to custom admin menu
- Get the last month with posts using a recursive function…
- Limiting woocommerce line_total decimal length
- Help with some php math in WordPress
- Use WP_Query in shortcode
- have_posts() execution failure
- How to add a second ‘place order’ button in WooCommerce [closed]
- How to filter posts by post format “standard” from wp-json api?
- Why is variable not working on custom sql query using wpdb?
- How to do multiple searches (with logical OR) in WP_Query in hook pre_get_posts?
- Change the URL of an image from wp_get_attachment_image_src except in the frontpage
- Can’t extend some core classes
- How do I display a user’s previous orders as a select box option on a product?
- Can’t search posts using WP_QUERY inside AJAX Function
- How to query for pages/post depending on slug?
- How do you add customer capability after Woocommerce purchase?
- Setting up 2 SMTP accounts: 1 for wordpress and 1 for woocommerce
- Change sign up fee in cart for subscription products WooCommerce
- write custom woocommerce templates and forms
- combine Code 1 with Code 2
- WooCommerce – Reset quantity input field when variation changes
- Get Current User Id Inside a Loop Returns 0 For a Shortcode
- get current product name in functions.php
- Retrieving Author ID in wp-admin area
- Get stock by custom meta field on all Woocommerce variable products
- Make the first item as default on Woocommerce product category items list
- Custom Text in WooCommerce Order Processing Email Based on Products
- Woocommerce redirect thankyou page based on product ID doesn’t empty Cart
- Set a condition based on WooCommerce checkout city field while placing order
- Get WooCommerce product details and transfer them to a custom DB table
- woocommerce subscriptions – get expiration date [closed]
- Random order of WP_Query results with highest meta value
- tracking number field in Woocommerce order [closed]
- Custom page archive query by url var calling page twice on one of my custom queries?
- WordPress custom slug (endpoint) and compare all links
- WooCommerce Related Products by Attribute
- Image as Sales Badge
- How to query for posts with a null or blank post_name?
- WordPress pagination not working with search page
- get current custom post ID by WP_Query method
- WooCommerce – Email admin with new user details
- Automatically remove a canceled order in Woocommerce
- How to securely provide a $_POST var in WP_Query with PHP 7?
- Using foreach loop breaks
- How to create a form and display its content as table in admin panel?
- Create WP_Query to search for posts by their categories or their parent/child categories
- Call global variable array() in woocommerce child/template
- WP Query with custom Shortcode
- wp_query with cat not working
- Remove price from Woocommerce variable product dropdown menu
- Advanced Meta Query for Large Calendar Website (12k+ posts) (175k+ wp_postmeta rows)
- How to use an associative array in post__in with WP_Query?
- Adding nofollow to a PHP generated Nav
- If Query In Sidebar
- Recent Posts slider, using WP_Query(), loads duplicate sliders
- Namespace spl_autoload problem in WordPress admin
- Compare post-IDs within WP_Query? (Less than / Greater than)
- Automated Cart Update With Alert Box Each Time
- Unreadable pagination
- remove wp floating submenu in wp dashboard
- Two Different Links for Same Product – WooCommerce [closed]
- Issue adding sub category programmatically
- WooCommerce/WordPress: how hide entire table form after submit (Admin Dashboard)?
- My custom wp-admin php files stopped working
- How to use $query->set with post__in?
- dividing sub-categories by parent category – WordPress
- Show prices with tax in Woocommerce Mini Cart [closed]
- Why do WP_Query results change after updating unrelated Advanced Custom Fields (ACF)?
- Woocommerce product variation backorder
- Status 400 for AJAX POST Request with admin-ajax.php
- Problem with custom plugin using AJAX to pull info from php file
- Woocommerce hook run after an Order been created through REST API
- How can I apply_filters from inside a function?
- Get and insert order email address to the PHP template inside HTML text
- Call to undefined function wp() in wp-blog-header.php
- Modify HTML structure of fields in woocommerce checkout form
- Pass Category Name, Description and Photo into variables to pass to jQuery
- Loading the same WP_Query in two different wordpress .php templates
- Auto-update products after they were published – Woocommerce
- How to prevent WP_Query function from returning all posts when empty?
- How to VAR_DUMP a $variable during checkout process (Is my product meta callable?)