WordPress.org

Forums

WooCommerce - excelling eCommerce
Query Products by Category ID, and Multiple Categories (3 posts)

  1. dankfresh
    Member
    Posted 1 year ago #

    I'd like to query products by a category ID, not slug, and also filter products that belong to more than 1 category. Something similar to WP_Query's category__and

    This is the syntax that works:

    $args = array(
            'posts_per_page' => -1,
            'product_cat' => 'category-slug-here',
            'post_type' => 'product',
            'orderby' => 'title',
        );
    	$the_query = new WP_Query( $args );
    	// The Loop
    	while ( $the_query->have_posts() ) {
    		$the_query->the_post();
    		echo '' . get_the_title() . '<br /><br />';
    	}

    Is it possible to filter the product categories by ID? Can I filter products by using an AND condition so they must belong to multiple categories (without 2 loops?)

    http://wordpress.org/plugins/woocommerce/

  2. dankfresh
    Member
    Posted 1 year ago #

    So, didn't realize this but product_cat can take multiple arguments, separated by commas. This acts like an "OR" statement, though, and doesn't produce the desired effect. I would like to find products that specifically belong to both.

  3. pou7777
    Member
    Posted 1 year ago #

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • WooCommerce - excelling eCommerce
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic