Created
December 31, 2012 14:10
-
-
Save anonymous/4419975 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** Register connection type (required for Posts 2 Posts plugin | |
https://github.com/scribu/wp-posts-to-posts/wiki/Basic-usage */ | |
function my_connection_types() { | |
p2p_register_connection_type( array( | |
'name' => 'classes_to_events', | |
'from' => 'class', | |
'to' => 'event', | |
'cardinality' => 'one-to-many' | |
) ); | |
} | |
add_action( 'p2p_init', 'my_connection_types' ); | |
/** Modify output for connections | |
https://github.com/scribu/wp-posts-to-posts/wiki/Actions-and-filters */ | |
add_filter( 'p2p_widget_html', 'my_p2p_template_handling', 10, 4 ); | |
add_filter( 'p2p_shortcode_html', 'my_p2p_template_handling', 10, 4 ); | |
function my_p2p_template_handling( $html, $connected, $ctype, $mode ) { | |
$template = locate_template( "p2p-{$mode}-{$ctype->name}.php" ); | |
if ( !$template ) | |
return $html; | |
ob_start(); | |
$_post = $GLOBALS['post']; | |
foreach ( $connected->items as $item ) { | |
$GLOBALS['post'] = $item; | |
load_template( $template, false ); | |
} | |
$GLOBALS['post'] = $_post; | |
return ob_get_clean(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment