pre_get_posts when loading calendar view with Ajax

Home Forums Calendar Products Events Calendar PRO pre_get_posts when loading calendar view with Ajax

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #67969
    inproma
    Participant

    Cheers guys!

    I have a filter running on pre_get_posts and it works fine as long as content is not loaded via Ajax.

    Specifically I am excluding some events from being displayed everywhere except in the very category they belong to. This works fine as long as I call up the corresponding view directly. Say all the events that I want to be hidden are in October (http://gastgewerbe-magazin.de/veranstaltungen/2013-10/), if I go there directly (empty/new tab, paste URL, hit Enter) the filter works fine. Now if I go there from another month, let it be September (http://gastgewerbe-magazin.de/veranstaltungen/2013-09) and then scroll down and use the “next month” link below the calendar the filter isn’t kicking in and all events are shown. You should be able to see the differences between the “ajaxified” version and the normal one quite easily.

    So I guess the Ajax call or they way how it retrieves the events (through tribe_get_view()?) somehow bypasses the pre_get_posts filter. Or I’m just plain stupid and can’t see what I’m doing wrong. 😛

    I’ll just paste in what I have in functions.php in my theme:

    function ggm_remove_events_from_display($query)
    {
    if
    (
    $query->query[‘post_type’] === ‘tribe_events’
    &&
    (
    array_key_exists(‘tribe_events_cat’, $query->query) === false
    ||
    (
    array_key_exists(‘tribe_events_cat’, $query->query) === true
    &&
    $query->query[‘tribe_events_cat’] !== ‘anuga-rahmenprogramm’
    )
    )
    )
    {
    $hide_categories_args = array
    (
    ‘taxonomy’ => ‘tribe_events_cat’,
    ‘terms’ => array(‘anuga-rahmenprogramm’),
    ‘field’ => ‘slug’,
    ‘include_children’ => true,
    ‘operator’ => ‘NOT IN’
    );

    $query->query[‘tax_query’][] = $hide_categories_args;
    }
    }
    add_filter(‘pre_get_posts’, ‘ggm_remove_events_from_display’);

    Btw, how do I post code snippets here? HTML tags seem to get swallowed.

    #68003
    Kelly
    Participant

    Hi, inproma. It sounds like you’re well on your way here.

    If you can wait, I’d recommend you hold off on further testing until our upcoming maintenance release, due out in a matter of days at this point. That may make things easier on you.

    For future reference, we’ve had good luck using PasteBin for code snippets. Really, any service like that is going to be your best bet.

    #981065
    Support Droid
    Keymaster

    This topic has not been active for quite some time and will now be closed.

    If you still need assistance please simply open a new topic (linking to this one if necessary)
    and one of the team will be only too happy to help.

Viewing 3 posts - 1 through 3 (of 3 total)
  • The topic ‘pre_get_posts when loading calendar view with Ajax’ is closed to new replies.