Support

Account

Home Forums Front-end Issues First get fields with date, then remaining fields.

Helping

First get fields with date, then remaining fields.

  • Hello,

    I’m building this site where I can add events as a cpt. These events contain a datepicker field and sort by upcoming dates (and doesn’t show when the date is over). Now I would like to have some events without a date that show when there’s less than 6 ‘actual’ events (containing a date), so there will always be 6 items on the page.

    This is my query

    $args = array(
    	'post_type'			=> 'events',
    	'posts_per_page' 	=> 6,
    	'orderby'			=> 'meta_value_num',
    	'order'				=> 'ASC',
    	'meta_query'		=> array(
    		array(
    			'key' => 'datum',
    			'type'	=> 'NUMERIC',
    			'value'	=> current_time('Ymd'),
    			'compare'	=> '>=', 
    		),
    	),
    );

    I hope my explanation was sufficient.

    Thanks in advance

  • You can’t do this in a single query and you’ll need to do 2 queries, one to get the posts with dates, keep track or how many are displayed and then to a second query to get posts that have no value and limit it to the number of spots you need to fill.

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

The topic ‘First get fields with date, then remaining fields.’ is closed to new replies.