3

I try sorting products (no Woocommerce, but created by custom post_type) in my site by price. I have two Advanced Custom Fields = price and price_sale. I need result like this:

 

  • 1999$
  • 2222$ (price_sale) 4000$
  • 3200$ (price_sale) 3600$
  • 3500$

I have this query arguments:

    

 {
        "categories": "sofas",
        "meta_query": {
           "relation": "AND",
           "1":{
              "relation": "AND",
              "query_one": {
                 "key": "price",
                 "type": "NUMERIC"
              },
              "query_two": {
                 "key": "price_sale",
                 "type": "NUMERIC"
              }
           }
        },
        "orderby": {
           "query_two": "ASC",
           "query_one": "ASC"
        }
     }

And result - all promotional products go after the usual while being sorted by price, like this:

  • 1999$
  • 3500$
  • 2222$ (price_sale) 4000$
  • 3200$ (price_sale) 3600$

I need them to sort through the two fields and displaying like as first example above.

Plikard
  • 179
  • 7

1 Answers1

0

I think the easiest was is to sort them after querying. However, you can achieve it by using this alternative, so that you won't have to sort by your own afterwards:

Add a filter on post_orderby WP Codex post_orderby Using this you could implement a sorting function which joins the both sorted sub-queries and resorts them.

I don't see another chance.

radscheit
  • 352
  • 4
  • 22