• I created a custom post type and I want the archive query to order the posts by

    • custom-field-1, which is a boolean field and returns either '1' or '0' in DESC order
    • custom-field-2, which contains text in ASC order (from A to Z)

    Question 1:
    How do approach this functionality? A meta_query does not offer multiple orderby options, does it? Neither does the new, more powerful orderbythat was introduced in WP 4.0 I guess?

    Question 2:
    If this is an option – how to use SQL JOIN in a pre_get_posts filter? Is that possible?

    Question 3:
    I don’t think it would be a nice solution but how about using two WP_Queries?

Viewing 1 replies (of 1 total)
  • You can add separately, like so:

    'orderby'=>'menu_order second_parameter'

    If you need an example more detailed, try this one:

    $custom_query = new WP_Query(array(
                    'post_type'=>'post',
                    'meta_query'=>array(
                                    array( 'key'=>'second_parameter', 'value'=>$foo, 'compare'=>'=' ),
                    ),
                    'meta_key'=>'second_parameter',
                    'orderby'=>'menu_order second_parameter',
                    'order'=>'ASC'
            ));
Viewing 1 replies (of 1 total)
  • The topic ‘orderby meta_value_num DESC and meta_value ASC’ is closed to new replies.