I have a really tricky function to implement and couldn't find a way by searching
Please see details below
I have a custom post type called "accommodation", and for this post type, there are 2 custom fields, one is "max_sleep_1", another one is "max_sleep_2"
Now the thing is for some posts under this post type, "max_sleep_1" is set and for other posts "max_sleep_2" is set, But I need to order all posts by max sleep number(the maximum one between this 2 fields)
post1 has "max_sleep_1" set to 1 and "max_sleep_2" set to 0
post2 has "max_sleep_2" set to 2 and "max_sleep_1" set to 0
post3 has "max_sleep_1" set to 3 and "max_sleep_2" set to 0
so the final order of post should be post1->post2->post3, so as you can see the problem, I am ordering by 2 fields, when "max_sleep_1" is set to 0 then I need to use "max_sleep_2" to sort
Hope you can understand what I am saying
I have been searching but couldn't find a proper solution, I also tried to merge this 2 fields after I get the results of WP_query, but also this didn't work.
Now I can only order by one field using meta key and the result is post1->post3->post2, like below
$args = array( 'post_type' => 'accommodation', 'paged' => get_query_var('paged'), 'post_parent' => $parent, 'meta_key' => 'max_sleep_1', 'orderby' => 'meta_value_num', 'order' => 'ASC' ); $the_query = new WP_Query( $args );
I will really appreciate it if anyone can help me out