Multi order not working
-
i need use multi order by menu_order => DESC us default
and + filters:
by date=> DESC or ASC
by different meta_key => DESC or ASC
My code in pre_get_posts action$orderby = array('menu_order'=> 'DESC', 'date'=>isset($_GET['order']) && !empty($_GET['order'])? $_GET['order'] :'DESC'); if(isset($_GET['orderprice']) && !empty($_GET['orderprice'])){ if($_GET['orderprice']=='ASC'){ $orderby['expect_price_from'] = $_GET['orderprice']; } else { $orderby['expect_price_to'] = $_GET['orderprice']; } } if(isset($_GET['ordercomment']) && !empty($_GET['ordercomment'])){ $orderby['comment_count'] = 'DESC'; } if(isset($_GET['orderreviews']) && !empty($_GET['orderreviews'])){ $orderby['rmp_vote_count'] = 'DESC'; } if(isset($_GET['orderrating']) && !empty($_GET['orderrating'])){ $orderby['rating'] = 'DESC'; } if(isset($_GET['ordercomment']) && !empty($_GET['ordercomment'])){ $orderby['comment_count'] = 'DESC'; } $query->set( 'orderby', $orderby);
End see in query WP_Query Object
[query_vars] => Array(
[s] => world
…
[orderby] => Array(
[menu_order] => DESC
[date] => DESC
[comment_count] => DESC
) )…
[request] => SELECT SQL_CALC_FOUND_ROWS kc_posts.ID FROM kc_posts WHERE 1=1 AND kc_posts.ID NOT IN (8,107,108,105,8,110,111) AND (((kc_posts.post_title LIKE ‘{6ed026e293c09705d8013d5b7ee9ff53fa30b364de672d5431486407900779c1}world{6ed026e293c09705d8013d5b7ee9ff53fa30b364de672d5431486407900779c1}’) OR (kc_posts.post_excerpt LIKE ‘{6ed026e293c09705d8013d5b7ee9ff53fa30b364de672d5431486407900779c1}world{6ed026e293c09705d8013d5b7ee9ff53fa30b364de672d5431486407900779c1}’) OR (kc_posts.post_content LIKE ‘{6ed026e293c09705d8013d5b7ee9ff53fa30b364de672d5431486407900779c1}world{6ed026e293c09705d8013d5b7ee9ff53fa30b364de672d5431486407900779c1}’))) AND kc_posts.post_type = ‘post’ AND (kc_posts.post_status = ‘publish’ OR kc_posts.post_status = ‘acf-disabled’ OR kc_posts.post_status = ‘private’) ORDER BY kc_posts.menu_order DESC, kc_posts.post_date DESC, kc_posts.comment_count DESC LIMIT 0, 10
But order of post by date only.
Do i something wrong?
How it works??Thanks for answer!
The page I need help with: [log in to see the link]
- The topic ‘Multi order not working’ is closed to new replies.