Home › Forums › Calendar Products › Events Calendar PRO › tribe_events post type being added to custom get_posts query
- This topic has 5 replies, 4 voices, and was last updated 9 years, 10 months ago by
pleek91.
-
AuthorPosts
-
June 2, 2016 at 6:24 am #1121577
pleek91
ParticipantHello,
I have the following query that is being run in a pre_get_posts action.
$args = array( 'post_type' => 'portfolio', 'fields' => 'ids', 'posts_per_page' => -1, 'tag__in' => [13] ); $portfolios = get_posts($args);Examining the resulting query with query monitor reveals that the post type ‘tribe_events’ is being added to the query.
SELECT wp_posts.ID FROM wp_posts INNER JOIN wp_term_relationships ON (wp_posts.ID = wp_term_relationships.object_id) WHERE 1=1 AND ( wp_term_relationships.term_taxonomy_id IN (13) ) AND wp_posts.post_type IN ('portfolio', 'tribe_events') AND ((wp_posts.post_status = 'publish')) GROUP BY wp_posts.ID ORDER BY wp_posts.post_date DESCIf I remove the
tag__inline the query works as expected, but with that line the ‘tribe_events’ post type shows up. If I disable The Events Calendar plugin the query works as expected with tag__in. I’ve also deactivated all plugins except the plugin running my query and the events calendar as well as switched to the default 2016 theme.June 2, 2016 at 8:34 pm #1122016Cliff
MemberHi. Thanks for your detailed question.
Are there any tribe_events posts (TEC Events) assigned to Tag ID 13?
June 3, 2016 at 7:31 am #1122141pleek91
ParticipantCliff,
I have two events in my dev environment and neither of them have any tags.
June 6, 2016 at 9:41 am #1123080Cliff
MemberHere’s some information I got from one of our developers:
Right now, things are constructed in such a way that queries referencing tags are expanded to include events in their scope, so what you’re experiencing is expected even if it isn’t ideal for your use case.
This may be a workaround for you (or at least lead you toward a solution of your own):
function remove_events_from_query( $query ) { $query->set( 'post_type', 'portfolio' ); } ); function disable_tribe_tag_query() { add_action( 'tribe_events_parse_query', 'remove_events_from_query' ); } function reenable_tribe_tag_query() { remove_action( 'tribe_events_parse_query', 'remove_events_from_query' ); }then…
disable_tribe_tag_query(); my_custom_query(); // (whatever you want to do here) reenable_tribe_tag_query();You may want to generalize it a little more to accommodate other cases
FYI: you could inspect the existing value via $query->get( ‘post_type’ ) and only modify it if it includes tribe_events for instance, but the code above should be able to guide you in the right direction for you to customize it to your needs.
Please let me know if this helped.
June 21, 2016 at 9:35 am #1129925Support Droid
KeymasterThis topic has not been active for quite some time and will now be closed.
If you still need assistance please simply open a new topic (linking to this one if necessary)
and one of the team will be only too happy to help. -
AuthorPosts
- The topic ‘tribe_events post type being added to custom get_posts query’ is closed to new replies.
