Viewing 7 replies - 1 through 7 (of 7 total)
  • Thread Starter mrwweb

    (@mrwweb)

    I thought that was all working, but it’s looking like AJAX still kicks in at times and removes the pre_get_posts changes I’m making. Super frustrating. This stuff all used to work.

    Brook

    (@brook-tribe)

    Howdy MRWweb,

    I have seen people disable Ajax by dequeueing Tribe Scripts. But, that has mixed results. It’s definitely not supported and will require you to rework some of our script magic. That probably does make a good feature request though. If you are keen to checkout our Uservoice page.

    To the topic at hand, you absolutely can modify tribe queries. Using pre_get_posts works, but you have to be in the right query which can be a bit difficult to target, and of course have the appropriate priority which is usually best set to 100. One surefire way to target the proper query and not worry about any of that is to use “tribe_events_pre_get_posts”, here is a rudimentary example of that:

    add_filter('tribe_events_pre_get_posts', 'filter_tribe_all_occurences');
    
    function filter_tribe_all_occurences ($wp_query) {
    
    	$te = TribeEvents::instance();
    
    	if(	$te->displaying == 'list' || $te->displaying == 'month'	) {
    
    		$wp_query->set( ... );
    
    	}
    
    	return $wp_query;
    }

    There you go! That should work for you. Let us know if you think there is an area of our documentation that could make this more clear. We are actually rewriting almost all of our documentation for the upcoming eventscalendarpro.com, and its documentation naturally still applies to the free plugin as well. But, even still just want to make sure we have hit all the right areas with our new documentation. Thanks!

    – Brook

    Thread Starter mrwweb

    (@mrwweb)

    Hi Brook,

    Thanks for the updates, but that doesn’t seem to work in all cases. Using this:

    add_filter('tribe_events_pre_get_posts', 'awc_filter_tribe_all_occurences',1000);
    function awc_filter_tribe_all_occurences ( $query ) {
    
    	$te = TribeEvents::instance();
    
    	if( $te->displaying == 'list' ) {
    		$query->set( 'cat', '16' );
    	}
    
    	return $query;
    }

    I get the correct queries (show events on from category 16 when in list view) when loading the page but the wrong events when AJAX kicks in via paging or use of the back button.

    For instance, if I

    1. Load an events page (maybe paged = 3)
    2. Click “Next Events”
    3. Click “Previous Events”

    I’m on the same “page” in steps 1 and 3 but the events listed are different. They’re correct in step 1 but not 3. This seems to be the same behavior described in this support thread on your site last year.

    So am I missing something or is support for pre_get_posts() and tribe_events_pre_get_posts() not working correctly?

    Hello all,
    As of some time we are having the following problem. When you hover over the event in the calendar all you see is code. Take a look by hovering over event in this months calendar via the link to our website. thank you!

    Thread Starter mrwweb

    (@mrwweb)

    @siliconvalleylatino, please open up a new thread about your issue instead of adding to this separate issue. (And when you do, include the code you’re seeing as that’s likely relevant to the problem.)

    Brook

    (@brook-tribe)

    Ahh that is fair MRWweb. The issue is that $te->displaying would equal null on ajax requests. Here is the line of code our plugin uses for situations like that:
    $displaying = ! empty( $query->query_vars['eventDisplay'] ) ? $query->query_vars['eventDisplay'] : TribeEvents::instance()->displaying;

    So with a var like that you could just detect if $displaying == list instead.

    I see you opened a different thread siliconvalleylatino. Thanks!

    – Brook

    @mrwweb I was having a similar issue with AJAX not working for my custom filter.

    I am not sure if the proper way, but it would not fire ‘tribe_events_pre_get_posts’ when checking to see it was not using the admin so I added an ajax check:

    if(!is_admin() || (defined( ‘DOING_AJAX’ ) && DOING_AJAX) ){
    add_action( ‘tribe_events_pre_get_posts’, ‘vf_filter_events’);
    }

    This is at least a starting point for me. Did you solve it another way?

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘[BUG] AJAX Views Ignore pre_get_posts’ is closed to new replies.