• Resolved Ceyar

    (@ceyar)


    Hello,

    I’m trying to make a wp_query with some arguments to get my output filtered by date and by time.

    In CFS I created a new CFS called “event_option” and into this i have created some new fields. It’s look like this:

    event_option
    – eve_date (date field)
    – eve_time (text field) -> ie. 12:30

    my goal is to display event ordered by date and if they are many event on same date, filter them by time(but the time is just number in a text field separate by “:” …).

    Here is my piece of code:

    $args = array(
    		'post_type' 	 => 'evenements',
    		'posts_per_page' =>  -1,
    		'order'          => 'ASC',
    		'orderby'        => 'meta_value',
    		'meta_query' 	 => array(
    			'relation'	 =>'AND',
            array(
                'key' 		 => 'eve_date',
                'value' 	 => date('Y-m-d'), // the current date
                'compare' 	 => '>='
            ),
            array(
            	'key'		 => 'eve_time',
            	'order'		 => 'ASC',
            	'orderby'	 => 'meta_value_num'
            	)
        ),
    	);

    My output goal would be something like this:

    Event1 10.10.2015 at 13:00
    Event2 10.10.2015 at 17:30
    Event3 22.10.2015 at 12:00

    Thank’s for this great plugin.
    I hope you have a solution. Thank you

    Best regards

    https://ww.wp.xz.cn/plugins/custom-field-suite/

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)

The topic ‘meta_query sorting by date and time’ is closed to new replies.