WP Query Order By Multiple Values

Question

I have created the following query. The query works perfectly. However, I despair with the order. I would like the posts in which the custom field “nft_featured” have the value “yes” to be first (the only options are yes or no) and then all other posts, sorted by the custom field “nft_datetime” (Date Field).

Thanks in advance!

<?php
    $args = array(
        'post_type'  => 'nft',
        'post_status' => 'publish',
        'posts_per_page' => '15',
        'no_found_rows' => 'true',
        'meta_key'=>'nft_datetime',
                
        
        'meta_query' => array(
        
            'relation' => 'OR',
            
            'date_clause' => array(
                    'key'     => 'nft_datetime',
                    'type'     => 'DATE',
                    'value'   => date('Y-m-d'),
                    'compare' => '>=',
                    ),
                
            
            'featured_clause' => array(
                    'key'     => 'nft_featured',
                    'value'   => 'yes',
                    'compare' => '=',
                    'type'   => 'CHAR',
                    ),
                ),
                
                
        'orderby' => array( 
            'featured_clause' => 'DESC', 
            'date_clause' => 'DESC', 
        ) 
                
    );
    
    echo build_query( $args );
    
?>  

0
Neil 4 months 2022-04-22T03:39:17-05:00 0 Answers 0 views 0

Leave an answer

Browse
Browse