Woocommerce query all products and categories

You can use wp_get_post_terms() $categories = wp_get_post_terms(get_the_ID(), ‘product_cat’, array(“fields” => “names”)); print_r($categories); The names of the product categories are returned as an array so you can either loop through them with a foreach or you can turn it into a string for example: $categories_list = implode(“,”, $categories); If you need more than just the names, … Read more

How to get all unique categories for posts in loop?

EDIT: Moved $i = 0 outside the loop. That should get you the full list of categories. $get_posts = new WP_Query(); $i = 0; $get_posts->query($args); if($get_posts->have_posts()) { $cats = array(); while($get_posts->have_posts()) { $get_posts->the_post(); $post_categories = wp_get_post_categories( get_the_ID() ); foreach($post_categories as $c){ $cat = get_category( $c ); $cats[$i] = $cat->slug ; $i++; } } //endwhile $result … Read more

WP_Query posts_per_page Only Bringing Back one post

Looks like you might be missing the wp_reset_postdata() in here. The WordPress codex shows you need to have a wp_reset_postdata() after your while loop. Here’s WordPress’ example (which even has the posts_per_page defined): <?php // example args $args = array( ‘posts_per_page’ => 3 ); // the query $the_query = new WP_Query( $args ); ?> <?php … Read more

Loop returning only 1 result

Near the top of your code, you have wp_reset_postdata();. As explained in the Functional Reference it alter the main loop and should be avoided. Looks like that’s what’s causing your issue.