// Define page-post-type connection
p2p_register_connection_type( array(
'id' => 'page-post-type',
'from' => 'page',
'to' => 'post-type',
'cardinality' => 'one-to-many',
'admin_box' => array('show' => 'from', 'context' => 'side')
) );
// Show Admin Box for page-post-type connection only on page with id 14
function restrict_p2p_box_display( $show, $ctype, $post ) {
if ( 'page-post-type' == $ctype->name) {
return($post->ID == 14);
}
return $show;
}
add_filter( 'p2p_admin_box_show', 'restrict_p2p_box_display', 10, 3 );
// Show page-post-type connections in homepage template
if ( is_front_page() ) :
if (function_exists('p2p_type')) {
$connected = new WP_Query( array(
'connected_type' => 'page-post-type',
'connected_items' => get_queried_object(),
'nopaging' => true
) );
if ($connected->have_posts() ) :
while ($connected->have_posts() ) : $connected->the_post();
the_title();
endwhile;
endif;
wp_reset_postdata();
wp_reset_query();
} else {
echo 'Plugin not found';
}
endif;