wp query – Sort by price woocommerce by ID post_meta

Question

There is an additional field in Posts (id_product), when using WP_Query I want to sort posts by meta _price (id_product).
How do I do this?

If I try to do so:

  $query->set( 'meta_key', '_price' );
  $query->set( 'orderby', 'meta_value' );
  $query->set( 'order', 'desc');

Sorting is done not by _price, but by the number specified in post_meta

0
WpGuest 4 months 2021-06-22T13:00:22-05:00 0 Answers 0 views 0

Leave an answer

Browse
Browse