• 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]

Viewing 1 replies (of 1 total)
  • By default, the built in posts do not have a Menu Order so they would all default to 0. The next thing in your orderby would be post_date which, if all the posts have a menu_order of 0 will then sort by this post_date field in descending order.

    Pages have a menu_order which you can see in the Page Attributes section. If you want to add a menu order to posts you would need to declare page attribute support for posts. See this answer on WordPress Stack Exchange by brasofilo

    I think a better solution would be a ordering plugin though that usually takes care of all the query modification for you. Something such as Post Types Order.

Viewing 1 replies (of 1 total)
  • The topic ‘Multi order not working’ is closed to new replies.