Sort Posts By Multiple Meta values then show other posts WordPress

I am working a nested wordpress query, I want sort posts by featured_article first then show another which not featured.

Then it should show up featured_articles plus another custom field order_value which will be bus, road, air etc

Read More

Here is my myquery

$args = array(
    'posts_per_page' => 10,
    'paged' => $paged,
    'orderby' => 'meta_value_num',
    'meta_key' => 'featured_article',
    'cat' => get_query_var('cat'),
            'meta_query' => array(
                'relation' => 'AND',
                      array('key' => 'order_value',
                                      'value' => 'bus',
                                        'compare' => 'LIKE'
                                ),
                         array('key' => 'featured_article',
                                        'compare' => 'EXISTS'
                                ),

                            )

Its working but its showing posts contain key value bus and fetured_article not other posts 🙁

Then i changed relation

'relation' => 'OR',

   $args = array(
        'posts_per_page' => 10,
        'paged' => $paged,
        'orderby' => 'meta_value_num',
        'meta_key' => 'featured_article',
        'cat' => get_query_var('cat'),
                'meta_query' => array(
                    'relation' => 'OR',
                          array('key' => 'order_value',
                                          'value' => 'bus',
                                            'compare' => 'LIKE'
                                    ),
                             array('key' => 'featured_article',
                                            'compare' => 'EXISTS'
                                    ),
                          array('key' => 'order_value',
                                          'value' => 'bus',
                                            'compare' => 'NOT LIKE'
                                    ),

                                )

Its working but not order by bus just order by featured_article

Related posts

Leave a Reply