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 correctly add Javascript in functions.php
- Woocommerce: How to override core functions in functions.php?
- Display featured products through custom loop in WooCommerce 3 [closed]
- spliting posts into two columns
- Changing layout with wp_customise
- How to use an associative array in post__in with WP_Query?
- Problem with custom plugin using AJAX to pull info from php file
- Is it possible to intercept all ajax requests and get the parameters and the returns?
- Exclude posts based on meta value
- Incorrect amount of posts returned when filtering related Woo products by custom taxonomy
- I’m trying to create an array with a foreach loop, but the array only stores the last item [closed]
- how can i add class or span tag at sprintf?
- WP_Query: How to get results from both meta_key options?
- Passing in MySQL prepare statement parameter separately throwing error
- How do I know if the user is a customer?
- posts_per_page displays only 2 posts instead of 4 posts
- WooCommerce is_product_category() not working
- Where does php code to load data go?
- Paged WP_Query is quitting on page 3
- Adding product permalink on admin order page throwing error
- Get Child of Child Pages in custom Menu
- Latest posts feed with a specific post always first
- How can i put php code on the wordpress page?
- jQuery doesn’t work in my php snippet
- Loop 1 user randomly
- Query seems to be duplicated
- Adding if statement to content for homepage
- Tables not showing divs and loop/php items
- How to add custom checkout field in user details mail template
- How to create a loop that will display one post and stop?
- Show button in header when product custom field is not empty
- How to change shipping method title based on cart amount?