Support

Home Forums Event Espresso Premium Hide postponed and cancelled events in Event List Query

Hide postponed and cancelled events in Event List Query

Posted: June 8, 2017 at 4:23 pm

Viewing 3 reply threads


psg_napkin_dev

June 8, 2017 at 4:23 pm

Hey Guys,

I’m trying to skip over events that are marked as cancelled or postponed on one specific loop on the home page. This is how I’ve set up my code so far.

<?php			
$atts = array(
	'title' => NULL,
	'limit' => 2,
	'css_class' => NULL,
	'show_expired' => FALSE,
	'month' => NULL,
	'category_slug' => NULL,
	'order_by' => 'start_date',
	'sort' => 'ASC'
);

$titles = array();
$dates = array();
$date_time = array();
$event_links = array();
$cities = array();
$images = array();
// run the query
global $wp_query;
$wp_query = new EventEspresso\core\domain\services\wp_queries\EventListQuery( $atts );
	if (have_posts()) : while (have_posts()) : the_post();
	
    $x = $post->EE_Event->first_datetime();
	
    $event_start = strtotime($x->start_date());
    $date_time[] = date("Y-m-d");
    $titles[] = get_the_title();
    $dates[] = date("M j, Y", $event_start);
    $event_links[] = get_permalink();
    $images[] = get_the_post_thumbnail_url();
$venue_obj = $post->EE_Event->venues();
$venue_obj = !empty( $venue_obj ) ? array_shift( $venue_obj ) : NULL;
if ( $venue_obj instanceof EE_Venue ) {
    $city = $venue_obj->city();
    
    $cities[] = ' - ' . $city;
}
else{
    $cities[] ="";
}
//}
do_action( 'AHEE_event_details_after_the_event_title', $post );

	endwhile;
	else:
?>
	No Upcoming Events
<?php 
    endif;
// now reset the query and postdata
wp_reset_query();
wp_reset_postdata();
?>

I later reuse these variables/arrays in the template to retrieve the data. I’ve marked one of the events as postponed, but it still shows up in the loop. How can I get around this?

Thanks,
Jason.


Josh

  • Support Staff

June 9, 2017 at 8:51 am

Hi Jason,

You can use the post_status parameter:

https://codex.wordpress.org/Class_Reference/WP_Query#Status_Parameters

e.g. 'post_status' => 'publish'

A bit off-topic, but with the way you have that loop set up where it’s pushing new elements onto arrays each time the loop iterates, that may cause some undesired results.


psg_napkin_dev

June 9, 2017 at 10:20 am

Hey Josh,

Thanks for the help as always! That was simpler than I thought.

Are you referring to undefined offsets?


Josh

  • Support Staff

June 9, 2017 at 11:03 am

I’m just not sure why you would push to multiple arrays like that.

Viewing 3 reply threads

The support post ‘Hide postponed and cancelled events in Event List Query’ is closed to new replies.

Have a question about this support post? Create a new support post in our support forums and include a link to this existing support post so we can help you.

Event Espresso