WordPress.org

Ready to get started?Download WordPress

Forums

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

  1. dankfresh
    Member
    Posted 7 months 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 7 months 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 2 months ago #

Reply

You must log in to post.

About this Plugin

About this Topic