TransWikia.com

How can I filter products by meta in Woocommerce REST API?

WordPress Development Asked by wpdaniel on October 30, 2021

I want filter products by meta_data in woocommerce rest api. I tried this, but not working:

$data = array(
                'numberposts'   => -1,
                'post_type'     => 'product',
                'meta_query' => array(
                    'relation'      => 'AND',
                    array(
                        'key'       => 'package_type',
                        'value'     => $filters['ad_type'],
                        'compare'   => '='
                    ),
                    array(
                        'key'       => 'package_location',
                        'value'     => $filters['ad_location'],
                        'compare'   => '='
                    ),
                    array(
                        'key'       => 'package_price_range',
                        'value'     => $filters['ad_price_range'],
                        'compare'   => '='
                    )
                )
            );

$_results = $this->woocommerce->get('products', $data);

It seems the $data filter is not prevail, it will get back the all product without filter. So the questions is, how can i use meta filters in api request?

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP