Last active
December 17, 2015 08:08
-
-
Save stephenharris/5577470 to your computer and use it in GitHub Desktop.
Simple shortcode to list events excluded by category
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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' ); | |
?> |
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
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