Your loop is wrong, you should not use to foreach inside the while, simply add the classic the_post () using the variable of your loop in this case $ loop
for example
<?php
$args = array(
'post_type' => 'product',
'stock' => 1,
'posts_per_page' => 9,
'product_cat' => $pagename,
);
$loop = new WP_Query( $args );
while($loop->have_posts()){
$loop->the_post();
?>
<div class="col-md-4">
<?php the_post_thumbnail(); ?>
</div>
<?php
}
?>
Related Posts:
- Query multiple custom post types in single loop
- Inject post (from specific category) between posts in Loop
- get product attributes for current product and store it in a variable
- Build a content and excerpt grid loop with paging and options for # of 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
- Alter secondary loop to exclude posts from current page category
- Woocommerce, recognize the loop of related products
- Woocommerce – How to get products which have a sale between 20% to 40%? [closed]
- Display related products with custom output
- How to get to a specific position in wp_query?
- How to select WooCommerce products by post_meta and order them
- have_posts() execution failure
- How can I use wp_query to show all product data using just the products ID?
- Using foreach loop breaks
- Display a specific category of products in shop page and disable code for specific actions
- Displaying Woocommerce Product Category in WordPress
- Woocommerce : Can’t get product info in loop
- 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
- WP_Query fails despite having 1 post
- wp_query get the 2nd post
- How to get post ID in a Page?
- Display an image if odd number of posts in grid
- How to add div blocks after certain set of post
- How to overwrite orderby with add_query_var
- get_the_ID() in the footer returns wrong value
- How to display SQL query that ran in WC_Order_Query?
- Get all posts as an array ID => Name
- Convert Featured products loop into Recent products loop?
- WordPress WP_Query without query GET parameters
- Do not duplicate posts with multiple categories in multiple loops
- Infinite Loop – WP_Query
- Dividing the loop to style post differently
- How to extract information from a wp_query result?
- Search.php gets metadata from first post
- the_post(); prints out style text into my HTML?
- Search AJAX Filters – Multiple Query Loops Into One Loop (Optimization)
- Wp Query : Order by distance lat,lon
- 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
- in_array not working on dev server but works on localhost
- Display all categories including sub categories under a list ul
- get_filtered_term_product_counts – Get product terms if any products
- Adding new divs with custom classes to products on WooCommerce shop page [closed]
- How to display sticky post always at the top (before regular post) in wordpress?
- WP_Query To Display Product Of Brand On Taxonomy Page
- Woocommerce Related Product by 2 taxonomy
- Making list of posts with chosen description
- wp_query beginner
- My query keeps looping infinitely ! how to stop it?
- Efficient way of querying for a “fallback” post?
- Display product attributes for current product
- For each 3 posts, show a different post type
- Add post class in custom loop (WP_QUERY)
- Create a hierarchical loop at predefined markup requirements
- WooCommerce – Print Processing orders [closed]
- Advanced Taxonomy query, with 3 post types
- Why does a meta_query break this WP_Query?
- WordPress post pagination on custom template not working
- Ajax Load More or View More functionality for woocommerce category layout by template overriding
- Pagination in category.php not functioning
- Woocommerce linking variations
- How to use a conditional statement in a post loop but not count towards the “posts_per_page” if false
- How do I exclude the current post from the upcoming post query
- 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
- How to show correct td of table tags in wp_query loop
- How could I prevent using the same custom loop in a template file when I only need to change one meta_query parameter?
- Very Slow Page – How to Optimize # of Queries?
- $wpdb->flush(); breaks the loop
- 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
- Use object in template part
- 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
- 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 first URL from post content
- 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