Support

Account

Home Forums Front-end Issues Ordering by Date with blank last

Helping

Ordering by Date with blank last

  • Consider…

    <? $args = array(
    'post_type'=> 'event',
    'posts_per_page' => -1,
    'meta_key' => 'type_0_date',
    'orderby' => 'meta_value',
    'order' => 'ASC'
    );

    I want to have events with ‘Coming soon’. So the first repeater Date field would be blank. This puts it first in the list, I’d like it last.

    I can do some hacky stuff with CSS; flex divs and ordering but, really, I’d like my results in the right order to start with.

    How do I achieve this?

  • Apparently this should work but doesn’t

    $args = array(
                'post_type'=> 'event',
                'posts_per_page' => -1,
                'meta_query' => array(
                    'date' => array(
                        'meta_key' => 'type_0_date',
                        'compare' => 'EXISTS',
                    ),
                    'tbc' => array(
                        'meta_key' =>'type_0_coming_soon',
                        'compare' => 'EXISTS',
                    )
                ),
                'orderby' => array(
                    'tbc' => 'DESC',
                    'date'=>'ASC'
                ),
    
            );
Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.