Home Forums General Issues Order Post By Custom Field


Order Post By Custom Field

  • Hi,

    I’m trying to do exactely what is described in the second example of the documentation (Getting featured custom posts first)

    So I created a Boolean checkbox to say if an article is featured or not. That works ok but only of posts where this value has been set (or has been set and the removed), and thus ignoring all posts where this field has never been checked (most of the posts).

    what is the best way to handle this situation? force that all post get this flag set? How do I handle the existing posts?

    I tried to do a double condition query but that does not result in the correct post order :

    ‘relation’ => ‘OR’,

    // Never featured
    ‘key’ => ‘Sticky’,
    ‘compare’ => ‘NOT EXISTS’

    // Featured but unpromoted
    ‘key’ => ‘Sticky’,
    ‘value’ => 1,
    ‘compare’ => ‘!=’

    Thanks for your help

  • The best solution I’ve found is this, see the first answer that uses a “post_results” filter.

Viewing 2 posts - 1 through 2 (of 2 total)

The topic ‘Order Post By Custom Field’ is closed to new replies.