pre_get_posts conflict with other custom post types?
-
Hi,
I wonder if anyone has had a similar problem to one I’m encountering in getting posts from The Events Calendar in to the loop. The problem is that when I place ‘tribe_events’ custom post type into the pre_get_posts action in my functions.php file it seems to trump all other custom post types on the site and the site only displays tribe_events’ posts.I can see that the Events Calendar plugin is making a series of pre_get_post actions in the files ‘/lib/tribe-event-query.class.php’ but looking at them I can’t specifically see which one could be causing the conflict. I also don’t want to start hacking away at as complex a plugin as the Events Calendar without some idea of what I’m doing.
For reference the code I’m using for the pre_get_posts is:
add_action( 'pre_get_posts', 'custom_post_archive' ); function custom_post_archive( &$query ) { if ( ( $query->is_author ) || ( $query->is_tag ) || ( $query->is_archive ) || ( $query->is_category ) ) $query->set( 'post_type', array('ourwork', 'tribe_events')); remove_action( 'pre_get_posts', 'custom_post_archive' ); // run once! }
Just to note I’ve tried altering the $priority of the action so that it’s executed after all the pre_get_posts actions that I could see in the plugin (e.g. add_action( ‘pre_get_posts’, ‘custom_post_archive’, 200 );) but that didn’t work.
Apologies if I’m duplicating topics, but was only able to find one other example of the problem (that didn’t really offer a solution that I found usable. Though it’s here for reference: https://tri.be/support/forums/topic/events-n-main-loop-tribe-events-and-regular-posts-what-happns-w-past-events/)
If anyone has any thoughts they’d be gratefully received.
- The topic ‘pre_get_posts conflict with other custom post types?’ is closed to new replies.