pre_get_posts Filtering Not Unhooked Properly

Home Forums Calendar Products Events Calendar PRO pre_get_posts Filtering Not Unhooked Properly

Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • #1007683
    Cliff
    Participant

    I’ve got a custom taxonomy that I can assign an event to. When I visit a URL like http://local.wordpress.dev/events/list/?tribe_region=5, it limits what I’m viewing to the given taxonomy (“region”), which is cool.

    The problem is, it hooks into pre_get_posts and never unfilters after use. This means running tribe_get_events, even before the main event list is displayed, results in a pre-limited query that I can’t seem to unset (and would have a hard time resetting, anyway).

    Can you help me get around this, and patch this up in the next release?

    Even though this is old, this might help: http://www.viper007bond.com/2010/02/02/wordpress-using-filters-with-get_posts/

    #1007976
    George
    Participant

    Hey Cliff,

    The problem is, it hooks into pre_get_posts and never unfilters after use. This means running tribe_get_events, even before the main event list is displayed, results in a pre-limited query that I can’t seem to unset (and would have a hard time resetting, anyway).

    Can you clarify all of the details here and how you came to this conclusion about things? e.g. when you say “it hooks into pre_get_posts”, what is “it” in your situation? Also, can you post any relevant code into Gists at http://gist.github.com or specify places in our code where you dug and found the problems that became your diagnosis here?

    Happy to investigate here – sorry you’ve run into some trouble with things. Elaborate on some more details and I’ll take a closer look and see what’s going on!

    Thanks,
    George

    #1008111
    Cliff
    Participant

    Sure!

    “It” is the TEC plugin, somewhere in Query.php. It’s doing the right thing by filtering events in the query to only include those associated with the taxonomy, but it seems to do so well before it’s needed, thus keeping this from working (you’ll see I currently exclude it when the given parameter is set): https://gist.github.com/logoscreative/970d9a18c9bdf0931549

    Basically, tribe_get_events() only returns events that are in the given taxonomy, despite me not explicitly requesting that in the query args.

    My guess is that it’s happening on line 357 of Query.php, but I could be wrong. Happy to give more details.

    #1008767
    George
    Participant

    Hey @Cliff,

    Thanks for sharing this…I’m not quite sure about the extent of this problem, and will investigate, but one thing I’m curious about is: why do you call global $post in your code? That is not necessary and itself could be causing some problems with your query results displaying on the page.

    Try removing that and see if anything is improved with your query. It looks fine to me otherwise and I don’t have problems using tribe_get_events() like you describe so am interested what you find.

    Let me know!
    George

    #1008917
    Cliff
    Participant

    I went that route because it seems to be the only way to use a given template TEC provides. :/

    Can I use tribe_get_template_part() with post data assigned to another variable?

    #1008946
    Cliff
    Participant

    Even after going through all the steps to not use $post or the tribe_get_template_part() function, the same still happens to me. tribe_get_events() is still getting filtered by custom taxonomy.

    #1009640
    George
    Participant

    Thanks for sticking with this Cliff – I can rope in a developer for further insight on the matter, but am wondering about one last thing: to be clear, does explicitly stating ‘suppress_filters’ => false in your tribe_get_events() call help things at all?

    As for using tribe_get_template_part(), you should be able to use that fine. If the $post variable there isn’t causing any problems, then feel free to roll back to that configuration.

    An example of explicit ‘suppress_filters’:


    $stickyargs = array(
    'posts_per_page' => - 1,
    'orderby' => 'menu_order',
    'order' => 'ASC'
    );

    $stickyevents = tribe_get_events( $stickyargs );

    Next, and finally for now, does moving the wp_reset_postdata(); call from inside the if ( $stickyevents ) { block to outside of this conditional block make any difference?

    Thanks for your patience with this!

    #1009949
    Cliff
    Participant

    I ended up going another route and just directly recreating most of the template—it was a bit too granular to dive into further just to save some code.

    Thanks for your help!

    #1010108
    George
    Participant

    Sorry I wasn’t able to help much Cliff – I appreciate the update though regardless!

    Best of luck with your site,
    George

Viewing 9 posts - 1 through 9 (of 9 total)
  • The topic ‘pre_get_posts Filtering Not Unhooked Properly’ is closed to new replies.