Shortcodes in widget: I need to exclude category

WordPress Event Management, Calendars & Registration Forums General Question Shortcodes in widget: I need to exclude category

This topic contains 6 replies, has 3 voices, and was last updated by  Stephen Harris 10 years, 11 months ago.

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #5711

    Can you tell me what the code looks like, if I want to exclude a category udsing shortcodes. Excluding by ID, that is.

    Best regards

    Steffen Innonet
    #5731

    Hi Steffen,

    Apologies for the delay in getting back to you on this!

    Unfortunately this isn’t possible with the [eo_events] shortcode. For something like this its probably easiest to create your own shortcode.

    The following should do roughly what you want.

    Usage: [events_excluded_cats exclude_cats="1,12,18"]

    add_shortcode( 'events_excluded_cats', 'innonet_events_excluded_cats_handler' );
    function innonet_events_excluded_cats_handler( $atts, $content = null ){
    
             $query = array( 
                  'numberposts'=>5, 
                  'event_start_after'=>'today', 
             );
    
             if( !empty( $atts['exclude_cats'] ) ){
                     $exclude = array_map( 'intval', explode( ',', $atts['exclude_cats'] ) );
                     $query['tax_query'] = array(
                    array(
                        'taxonomy' => 'event-category',
                        'operator' => 'NOT IN',
                        'terms' => $exclude,
                        'field' => 'id',
                    )
                    );
             }
    
           //Return mark-up of list (can use eventorganiser_list_event for simplicity).
           return eventorganiser_list_events( $query, array(), 0 );
    }
    
    Stephen Harris
    #5738

    Thanks for the reply Stephen

    This is what my code in my text widget looks like:

    [eo_events numberposts=”6″ exclude_category=”93″ eo_events showpastevents=false] %start{j. F}% – %event_title% [/eo_events]

    Se kalender

    So my question is; In what file do I insert your piece of php code and will I just throw in [events_excluded_cats exclude_cats=”1,12,18″] in the above code in the widget as well?

    Thanks

    Steffen Innonet
    #5739

    Hey Steffen,

    You can add that code to several different parts of the WordPress back-end such as in the functions.php file or in a custom plug-in.

    Have a read of this post which explains it all: http://wp-event-organiser.com/blog/tutorial/where-should-i-put-code-from-the-tutorials/

    Dario
    #5742

    Ok. Thanks. I´ll put the code in my functions.php

    But what about the little bit of short code? So what about the short code – will I just throw in [events_excluded_cats exclude_cats=”1,12,18″] in the widget as well?

    Steffen Innonet
    #5837

    Could anyone of you guys answer my last question on this thread about the bit of short code in the widget please?

    Steffen Innonet
    #5842

    Hi Steffen,

    Apologies, your reply slipped my radar…

    [events_excluded_cats exclude_cats="1,12,18"] would be used instead of the [eo_events] shortcode

    However, if you want to use the template tags you’ll need to make the following alterations:

    Just before return eventorganiser_list_events( $query, array(), 0 ); put

    $args = array(
                'class'=>'eo-events eo-events-shortcode',
                'template'=>$content,
                'no_events'=>'',
                'type'=>'shortcode',
            );
    

    and replace

     eventorganiser_list_events( $query, array(), 0 );
    

    with

    eventorganiser_list_events( $query, $args, 0 );`
    

    I’ve created this gist with an update version of the above code.

    Stephen Harris
Viewing 7 posts - 1 through 7 (of 7 total)
To enable me to focus on Pro customers, only users who have a valid license for the Pro add-on may post new topics or replies in this forum. If you have a valid license, please log-in or register an account using the e-mail address you purchased the license with. If you don't you can purchase one here. Or there's always the WordPress repository forum.