Saturday, January 14, 2023
HomeWordPress Developmentmeta question - Ordering WP_Query outcomes by second meta_key

meta question – Ordering WP_Query outcomes by second meta_key


I’ve received code that at the moment returns outcomes of a question based mostly on a meta_query (whether or not or be aware the present date is previous a saved key “ex_closing_date” – or has no time limit in any respect.

The question for that is:

$args = array(
    'posts_per_page' => $post_count,
    'post_type'      => 'exhibition',
    'tax_query'      => array(
        array(
            'taxonomy' => 'exhibition_cat',
            'area'    => 'id',
            'phrases'    => $classes,
            'operator' => 'IN',
        ),
    ),
    'meta_query'     => array(
        'relation' => 'OR',
        array(
            'key'     => 'ex_closing_date',
            'worth'   => $at present,
            'evaluate' => '>=',
            'kind'    => 'date',
        ),
        array(
            'key'     => 'ex_closing_date',
            'worth'   => '',
            'evaluate' => '=',
        ),
        'orderby'  => 'publish_date',
        'order'    => 'DESC',
    ),

);

Nevertheless, the publish additionally comprises a True/False boolean for whether or not the publish might be thought-about “Precedence” – and moved to the highest. That is saved in ex_priority as 1/0 (through Superior Customized Fields) To do that, I need to type the outcomes of this checklist by ex_priority first, then by publish date.

I attempted to vary the ‘orderby’ to this:

'orderby'  => 'meta_value_num publish_date',
'meta_key' => 'ex_priority"

however the one publish it provides me is the one marked with precedence – not one of the others.

I would like a option to get it, so I solely get the outcomes which can be throughout the time limit, however with those marked with ex_priority up the highest. The publish is a customized kind that doesn’t have sticky publish performance, so I can not use that.

I’ve learn some stuff about combining meta_keys – however it then provides me EVERYTHING within the database – not one’s restricted by the time limit.

Any assistance is appreciated.
Thanks

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments