Support » Plugin: ICS Calendar » Hide individual entries in the calendar

  • Resolved BrandBull

    (@brandbull)


    Hello,

    first of all thank you for your great plugin. Well done with lots of great options !!!!!

    I only want to display appointments from my Apple calendar that have a specified location. How can I set a filter that, for example, only shows events with a specific location from my calendar? All other calendar events are not displayed.

    Thank you + best regards
    Olli

    The page I need help with: [log in to see the link]

Viewing 12 replies - 1 through 12 (of 12 total)
  • Thread Starter BrandBull

    (@brandbull)

    … in my Testcalendar ist the only event with a location:
    Monday 21. December = TEST / Gubener Straße

    Plugin Author room34

    (@room34)

    Unfortunately, there’s not really a way to filter the list in this way right now.

    If it’s possible for you to set up a second calendar that just has those events, that would be an option. Another possibility, though it wouldn’t actually keep the other events from appearing in the HTML (but they would not display on the page), would be to fake it with some jQuery. Something like this might work:

    
    jQuery('.ics-calendar-list-wrapper .location').each(function() {
        if (jQuery(this).text().indexOf('Gubener Straße') == -1) {
            jQuery(this).closest('.event').remove().prev('.time').remove();
        }
    });
    jQuery('.ics-calendar-list-wrapper h4').each(function() {
        if (jQuery(this).next('dl').children('dd').length == 0) {
            jQuery(this).remove();
        }
    });
    

    That would take all events that do not contain “Gubener Straße” in the location out of the page, and then remove any date headers if their event list is now empty.

    (Note: I haven’t actually tested this code. I’m not 100% sure the .prev('.time').remove() will work after the .event has already been removed, so you might need to split that into two lines and remove the .time first.)

    Thread Starter BrandBull

    (@brandbull)

    Thank you for your feedback!
    The jOuery script would be enough for me. Where do I have to use or copy it. what do I have to write in to the shortcode?

    Plugin Author room34

    (@room34)

    I just remembered there’s a better way to do this.

    There’s a filter called r34ics_display_calendar_filter_ics_data. In your theme’s functions.php file you could use:

    
    add_filter('r34ics_display_calendar_filter_ics_data', function($ics_data) {
        foreach ((array)$ics_data['events'] as $key => $event) {
            if (strpos($event['location'], 'Gubener Straße') === false) {
                unset($ics_data['events'][$key]);
            }
        }
        return $ics_data;
    });
    

    This will actually remove those events from the data before rendering, so it’s not in the HTML at all, and you wouldn’t need to do anything funny with jQuery.

    Thread Starter BrandBull

    (@brandbull)

    i have copy this to my theme function. but by now, it shows me no events – but i have now no event with “Gubener Straße” in my calendar…. ?

    • This reply was modified 1 year, 8 months ago by BrandBull.
    Thread Starter BrandBull

    (@brandbull)

    My Shortcode is like this:

    [ics_calendar url=”webcal://p39-caldav.icloud.com/published/2/Mjc0MDg5MjYwMjc0MDg5MpPy4gAYuun5hgl6QNH7-RjbO1JKJ3XtQPxRRPlhBnv2yB2vCg5HeT5nEAhUNBMPQSC1-CzBtmcjrhpwoXxcKMI” title=”DISPLAY_TITLE” view=”list” count=”15″ color=”#ffffff #008000 #ffa500″ hidetimes=”true” skip=”NUMBER” location=”true”]

    Thread Starter BrandBull

    (@brandbull)

    … did you have a solution for me, why this is not working or no event will display on my calendar ?

    Plugin Author room34

    (@room34)

    Sorry, it’s been a while since I’ve worked with some of these filters. The one I gave you was incorrect. Please delete that first code block and use this instead:

    
    add_filter('r34ics_display_calendar_exclude_event', function($exclude, $event, $args) {
    	if (empty($event->location) || strpos($event->location, 'Gubener Straße') === false) {
    		$exclude = true;
    	}
    	return $exclude;
    }, 10, 3);
    
    Thread Starter BrandBull

    (@brandbull)

    … unfortunately this block doesn’t work either … 🙁 … do you have another solution? Thanks, Olli

    Thread Starter BrandBull

    (@brandbull)

    … sorry, now it works… can i spend you some beer?

    Plugin Author room34

    (@room34)

    Glad it works now! I didn’t mention that you might need to add reload=”true” to bypass the built-in caching to get it working immediately.

    Thread Starter BrandBull

    (@brandbull)

    yeah, works perfect…. THANK YOU!!!!!!!!!

Viewing 12 replies - 1 through 12 (of 12 total)
  • The topic ‘Hide individual entries in the calendar’ is closed to new replies.