1

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',
          ),
        ),
    );
2
  • Well, I guess you mistakenly put that meta query in the tax_query.. You should put it in a meta_query, i.e. 'meta_query' => array( array( ... ) ).
    – Sally CJ
    Feb 3, 2021 at 9:26
  • 1
    Thanks @SallyCJ , Now just show instock status
    – och
    Feb 3, 2021 at 9:33

1 Answer 1

1

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'
      )
    )
);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.