Answer the question
In order to leave comments, you need to log in
How to make complex orderby in WP_QUERY?
I have 2 fields: min_variation_price , max_variation_price
In wp_query I write the following parameters:
'orderby' => 'min_variation_price max_variation_price',
'order' => 'ASC'
Everything works, but there is 1 problem, one of the fields can be empty and they fall to the begining.
I need to make the empty field go to the end.
Tell me how to implement this in wp_query
When I wrote a manual query, I did this:
CASE WHEN pmeta.meta_value = '' THEN '99999' END, pmeta.meta_value ASC
Answer the question
In order to leave comments, you need to log in
Solved the problem:
add_filter( 'posts_orderby', array( $this, 'query_orderby' ) );
$gmw_query = new WP_Query( $this->form['query_args'] );
remove_filter( 'posts_orderby', array( $this, 'query_orderby' ) );
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question