Question

I want show (featured product) that instock, but this query just show in stock products.

$query = array(
        'post_type' => 'product',
        'post_status' => 'publish',
        'posts_per_page' => 12,
        'orderby' => 'date',
        'order' => 'DESC',
        'meta_query' => array(
          'relation' => 'AND',
          array(
            'key' => '_stock_status',
            'value' => 'instock',
          ),
          array(
              'taxonomy' => 'product_visibility',
              'field' => 'name',
              'terms' => 'featured',
          ),
        ),
    );
Was it helpful?

Solution

You mixed meta query and tax query

It should look like this

$query = array(
    'post_type' => 'product',
    'post_status' => 'publish',
    'posts_per_page' => 12,
    'orderby' => 'date',
    'order' => 'DESC',
    'meta_query' => array(
      array(
        'key' => '_stock_status',
        'value' => 'instock'
      )
    ),
    'tax_query' => array(
      array(
          'taxonomy' => 'product_visibility',
          'field' => 'name',
          'terms' => 'featured'
      )
    )
);
Licensed under: CC-BY-SA with attribution
Not affiliated with wordpress.stackexchange
scroll top