Home › Forums › Calendar Products › Events Calendar PRO › pre_get_posts Filtering Not Unhooked Properly
- This topic has 8 replies, 2 voices, and was last updated 8 years, 7 months ago by George.
-
AuthorPosts
-
September 22, 2015 at 5:31 pm #1007683CliffParticipant
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 runningtribe_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/
September 23, 2015 at 11:57 am #1007976GeorgeParticipantHey 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,
GeorgeSeptember 23, 2015 at 4:33 pm #1008111CliffParticipantSure!
“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.
September 25, 2015 at 11:10 am #1008767GeorgeParticipantHey @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!
GeorgeSeptember 26, 2015 at 6:37 am #1008917CliffParticipantI 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?
September 26, 2015 at 7:28 am #1008946CliffParticipantEven 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.
September 29, 2015 at 7:11 am #1009640GeorgeParticipantThanks 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!
September 30, 2015 at 5:08 am #1009949CliffParticipantI 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!
September 30, 2015 at 10:06 am #1010108GeorgeParticipantSorry I wasn’t able to help much Cliff – I appreciate the update though regardless!
Best of luck with your site,
George -
AuthorPosts
- The topic ‘pre_get_posts Filtering Not Unhooked Properly’ is closed to new replies.