• Resolved studiowizjo

    (@studiowizjo)


    I need to get all Woocommerce product variations that belongs to selected category. I tried to query that this way:

    
    $args = array(
        'post_type' => 'product_variation',
        'post_status' => array('private', 'publish'),
        'tax_query' => array(
            array(
                'taxonomy' => 'product_cat',
                'field' => 'term_id',
                'terms' => $selected_category_id
            )
        )
    );
    
    $variations = get_posts( $args );
    

    but “tax_query” part seems to be ignored and no matter what will be provided inside, it does not affect the query.

    Any ideas how to do that?

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Support RK a11n

    (@riaanknoetze)

    This is a fairly complex development topic. I’m going to leave it open for a bit to see if anyone is able to chime in to help you out.

    I can also recommend the following places for more development-oriented questions:
    * WooCommerce Slack Community: https://woocommerce.com/community-slack/
    * Advanced WooCommerce group on Facebook: https://www.facebook.com/groups/advanced.woocommerce/

    “tax_query” is not a valid parameter for that function. Just use “category” and the ID:

    $args = array(
        'post_type' => 'product_variation',
        'post_status' => array('private', 'publish'),
        'category' => $selected_category_id
    );
    
    $variations = get_posts( $args );
    Thread Starter studiowizjo

    (@studiowizjo)

    @screenload: Unfotunately, that doesn`t work. It gives me always empty results.

    Luminus Alabi

    (@luminus)

    Automattic Happiness Engineer

    @studiowizjo,

    As @riaanknoetze mentioned, you’d be best served by either reaching out to a developer or asking in the more developer oriented communities that he linked you to above.

    I’ll go ahead and mark this as solved as this isn’t something we’d be able to dig into for you here.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Get all product variations by category’ is closed to new replies.