• Resolved jdwilliams83

    (@jdwilliams83)


    Hello,
    I am attempting to create a custom query to order the event posts by event start date as compared to the current date. The goal is to to display the events in ascending order that are greater than are equal to the current date.

    Do you know a way of doing this?

    Currently my method isn’t working. Not sure this is possible with the below code since the date field is outputted as a string?

    Thanks for your assistance.

    Here’s my Code:
    `$args = array (
    ‘post_type’ => ‘facebook_events’,
    ‘posts_per_page’ => 6,
    ‘meta_query’ => array(
    ‘key’ => ‘event_starts’,
    ‘value’ => date(‘Ymd’),
    ‘compare’ => ‘>=’
    ),
    ‘orderby’ => ‘meta_value’,
    ‘order’ => ‘ASC’

    );

    https://wordpress.org/plugins/facebook-events-importer/

Viewing 1 replies (of 1 total)
  • Plugin Author WPTrashPanda

    (@jprescher)

    There is a hidden sort field you could try:

    <?php
    event_starts_sort_field
    ?>

    If you don’t want to use the current date you should be able to use it with your query.

    <?
    $currentdate = date("Y-m-d",mktime(0,0,0,date("m"),date("d")-1,date("Y")));
    
    		$args = array (
                      	'meta_query'=> array(
    	                    array(
    	                      'key' => 'event_starts_sort_field',
    	                      'compare' => '>',
    	                      'value' => $currentdate,
    	                      'type' => 'DATE',
    	                    )),
    		    'post_type' => 'facebook_events',
    			'posts_per_page' => $max,
    			'paged' => $paged,
    	        'meta_key' => 'event_starts_sort_field',
               'orderby'=> 'modified',
                'order' => 'DESC',
    
    		);
    ?>

Viewing 1 replies (of 1 total)

The topic ‘Order by Start Date’ is closed to new replies.