WordPress.org

Forums

The Events Calendar
[resolved] pre_get_posts conflict with other custom post types? (2 posts)

  1. EddJB
    Member
    Posted 1 year ago #

    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.

    https://wordpress.org/plugins/the-events-calendar/

  2. leahkoerper
    Modern Tribe Support Rep
    Plugin Author

    Posted 1 year ago #

    Hi EddJB,

    As outlined in our forum guidelines, we aren’t able to help with these kinds of customizations. Hopefully another user here will be able to help you out. We also have some handy resources that might be helpful for you:

    Themer's Guide - provides an overview of how to customize the plugin's frontend appearance.
    Tutorials - useful tips and tricks for changing how the plugin looks and behaves.
    Technical Docs - provides an overview of the classes and functions in each plugin

    Good luck, and thanks for using The Events Calendar!

    ~Leah

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • The Events Calendar
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic