• Hello,

    i’m trying to order the next events displayed on my site by start date.

    but i’m not arriving to do it.

    i tryed different way, but events never shows up in the good order.

    this is my query args :

    	'post_type'=> 'event',
    	'orderby' => 'event_start_date',
    	'order'    => 'ASC',

    any help will be apreciate.
    thanks in advance for your help

Viewing 1 replies (of 1 total)
  • Plugin Support angelo_nwl

    (@angelo_nwl)

    this might not work out of the box but it might give you some idea

    
    function my_em_wp_query(){
    	$args = array(
    		'post_type' => 'event',
    		'posts_per_page' => 100,
    		'meta_query' => array( 'key' => '_start_ts', 'value' => current_time('timestamp'), 'compare' => '>=', 'type'=>'numeric' ),
    		'orderby' => 'meta_value_num',
    		'order' => 'ASC',
    		'meta_key' => '_start_ts',
    		'meta_value' => current_time('timestamp'),
    		'meta_value_num' => current_time('timestamp'),
    		'meta_compare' => '>='
    	);
    
    	// The Query
    	$query = new WP_Query( $args );
    
    	// The Loop
    	while($query->have_posts()):
    	$query->next_post();
    	$id = $query->post->ID;
    	echo '<li>';
    	echo get_the_title($id);
    	echo ' - '. get_post_meta($id, '_event_start_date', true);
    	echo '</li>';
    	endwhile;
    
    	// Reset Post Data
    	wp_reset_postdata();
    }
    add_shortcode('em_wp_query','my_em_wp_query');
    
Viewing 1 replies (of 1 total)
  • The topic ‘Sort events by date in custom query’ is closed to new replies.