Skip to content

Instantly share code, notes, and snippets.

@codearachnid
Created October 2, 2012 02:34
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save codearachnid/3815849 to your computer and use it in GitHub Desktop.
Save codearachnid/3815849 to your computer and use it in GitHub Desktop.
Fix compatibility issues with The Event Calendar and Posts 2 Posts WordPress Plugins
<?php
/**
* Fix compatibility issues with The Event Calendar and Posts 2 Posts WordPress Plugins
* Issue arrises with how nested select queries function when P2P expects a single column.
*/
function tribe_to_p2p_pre_get_posts_20121001( $query ){
if(isset($query->_p2p_capture) && $query->_p2p_capture) {
add_filter( 'posts_fields', 'tribe_to_p2p_setupFields_20121001', 20);
} else {
remove_filter( 'posts_fields', 'tribe_to_p2p_setupFields_20121001', 20);
}
return $query;
}
function tribe_to_p2p_setupFields_20121001( $fields ){
global $wpdb;
$fields = "{$wpdb->posts}.ID";
return $fields;
}
add_action( 'pre_get_posts', 'tribe_to_p2p_pre_get_posts_20121001');
@notasausage
Copy link

I put this in my functions.php file after having issues with the many-to-many relationship in Posts 2 Posts connections when using Event Calendar and it worked like a charm.

@tannerm
Copy link

tannerm commented Dec 12, 2013

Thanks for this! I found that I also needed to add:

$query->query_vars['eventDisplay'] = 'custom';

under the add_filter call.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment