Skip to content

Instantly share code, notes, and snippets.

@stephenharris
Last active December 17, 2015 08:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stephenharris/5577470 to your computer and use it in GitHub Desktop.
Save stephenharris/5577470 to your computer and use it in GitHub Desktop.
Simple shortcode to list events excluded by category
<?php
/**
* Simple shortcode to list events excluded by category
* @see http://wp-event-organiser.com/forums/topic/shortcodes-in-widget-i-need-to-exclude-category/
*
* ## Usage
* [events_excluded_cats exclude_cats="1,12,18"]
*/
function innonet_events_excluded_cats_handler( $atts, $content = null ){
$taxs = array('category','tag','venue');
foreach ($taxs as $tax){
if(isset($atts['event_'.$tax])){
$atts['event-'.$tax]= $atts['event_'.$tax];
unset($atts['event_'.$tax]);
}
}
if((isset($atts['venue']) &&$atts['venue']=='%this%') ||( isset($atts['event-venue']) && $atts['event-venue']=='%this%' )){
if( eo_get_venue_slug() ){
$atts['event-venue']= eo_get_venue_slug();
}else{
unset($atts['venue']);
unset($atts['event-venue']);
}
}
if( !empty( $atts['exclude_cats'] ) ){
$exclude = array_map( 'intval', explode( ',', $atts['exclude_cats'] ) );
$atts['tax_query'] = array(array(
'taxonomy' => 'event-category',
'operator' => 'NOT IN',
'terms' => $exclude,
'field' => 'id',
));
}
$args = array(
'class'=>'eo-events eo-events-shortcode',
'template'=>$content,
'no_events'=>'',
'type'=>'shortcode',
);
//Return mark-up of list (can use eventorganiser_list_event for simplicity).
return eventorganiser_list_events( $atts, $args, 0 );
}
add_shortcode( 'events_excluded_cats', 'innonet_events_excluded_cats_handler' );
?>
@FriendlyWP
Copy link

Just a note, I couldn't get this to work without adding event_start_after="now" to the shortcode, eg:

[events_excluded_cats exclude_cats="1,12,18" event_start_after="now"]

Without that, I got a fatal error:
PHP Fatal error: Call to a member function format() on a non-object in ...\wp-content\plugins\event-organiser\includes\event-organiser-event-functions.php on line 1093

thanks! Michelle

@CharlieEtienne
Copy link

Thank you for this ! Just a question, how could I use this with [event_board] ?

Thanks,

Charlie

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment