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
- How to remove “out of stock” variation options from size dropdown in woocommerce?
- Get WooCommerce shipping methods programmatically
- Add a custom text field to WooCommerce admin product data “Variations”
- Translating add to cart woocommerce button [closed]
- Display Post co-authored in Author Page
- Add attribute / custom attribute to product in woocommerce
- Sorting Posts | Alphabetical Order
- Looking for most performant way to execute several similar WP queries within shortcodes
- Help with some php math in WordPress
- How do I display a user’s previous orders as a select box option on a product?
- combine Code 1 with Code 2
- Adding nofollow to a PHP generated Nav
- Automated Cart Update With Alert Box Each Time
- Two Different Links for Same Product – WooCommerce [closed]
- WooCommerce/WordPress: how hide entire table form after submit (Admin Dashboard)?
- Reload part of checkout on changed shipping method
- Woocommerce related product text
- How to make my custom widget appear within WordPress widgets? Plugin development
- Function works when I don’t login to WordPress but when I login then it doesn’t work
- WordPress, AJAX and pre_get_posts using conditional tags
- How to make products with no cost in WooCommerce
- Incorrect amount of posts returned when filtering related Woo products by custom taxonomy
- WordPress admin is incredibly slow [closed]
- Remove echo from shortcode
- How Can I use WP_Query to Only Display 1 Post from Custom Post Type if Query Returns Posts with Matching ID in Custom Field
- unable to use ‘new WP_Query’ in AJAX call
- How to remove coupon dropdown feature
- Add html link in functions.php files of the theme
- Add product to cart for user – WC()->cart->add_to_cart [closed]
- Display attribute on shop page after the title
- WooCommerce – Moving Product Price to the Left of Add to Cart Button [closed]
- How to hide posts of a specific custom category in WordPress?
- Where to copy woocommerce files to in my custom theme to avoid editing the core plugin?
- Have Woocommerce show product price if id, when not logged in
- I installed WordPress locally now how do I login?
- How to debug failed changes to posts?
- displaying a fall back query if there’s nothing in the post-type category
- Custom reduce stock code affecting date_modified – How to bypass?
- Isn’t Returning Value While Using SELECT COUNT(*) FROM {$wpdb->prefix}
- wp_query with multiple arguments with AND
- Nested Queries of decreasing specificity
- Wrong pagination results, page counter resets when navigating
- How can I update WordPress plugins or WordPress itself in all server?
- WooCommerce Query Product Titles
- Is it possible to order posts using multiple meta queries, i.e. show posts from first meta query, then the second?
- How to add a shortcode which runs a .php file for the current post
- WP query posts BUT show the most recent and one per author
- Variant Item SKU as Product Code
- Run a sql (update) after 12 hours after the user login. Woocommerce users
- Define global custom post
- Add a new view on the Woocommerce account page
- Class ‘WP_Privacy_Requests_Table’ not found
- Use Search Term in html link and redirect
- How to get content on a blank basket/cart page in a custom theme with woocommerce
- Looping through and combining calls to Woocommerce REST API
- How to import woocommerce custom fields data into another site?
- Woocommerce – if selected attribute term equals
- split 1 cart item into instock and back ordered
- How to separate the taxonomies list from the form so that editing taxonmies is the same as pages and posts?
- Hide price excluding tax when price is empty
- Woocommerce variable products are being added to the card on the homepage (ajax)
- How to detect if a revision was made by woocommerce or wordpress?
- Efficient way of querying for a “fallback” post?
- How do I prevent a folder from reappearing in my home directory?
- Create a hierarchical loop at predefined markup requirements
- Use WP_Query Data In Cookie
- Styling admin page rows in order of importance (checkboxes)
- Keeping the previous get value and add another value when submitted
- Add specific phrase after every product title including the discounted price? [closed]
- Pagination in category.php not functioning
- Display Sale Price Before Regular Price (WooCommerce)
- Setting WooCommerce currency programmatically
- How do I change the Go To Categories link in the term_updated_messages
- WooCommerce – Show ‘Sales’ badge on variable products where only some variations have sales price [closed]
- How to create a container in php then customise it in CSS
- Remove Woocommerce product from cart with ajax/fetch
- Automatically change insurance quantity based on cart total [closed]
- WooCommerce Modal Fly cart on add to cart – With AJAX
- /page/2/ redirect to 404
- Hide ‘Downloadable’ and ‘Virtual’ checkbox options from Woocommerce Variations?