• I’m using WP_Query($args) to populate a search result of custom post types.

    I want to sort the results based on a post meta value named offer_id.

    Aim is to bring the posts with this meta key set to the top of the search results.

    When I tried,

    $args = .....
    $args['meta_query'] = array(....);
    $args['meta_query']['offers'] =
    array(
        'key'=>'offer_id',
        'compare' => 'EXISTS',
    );
    $args['orderby']  = 'meta_value';

    Only custom posts having offer_id meta value included in the results, posts without offer_is meta value are not included.

    How can I show the posts with meta key offer_id on the top of the query results and posts without meta key on the bottom?

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘How to show posts with a meta key on the top of the query results rest after tha’ is closed to new replies.