Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Define page-post-type connection
- p2p_register_connection_type( array(
- 'name' => 'page-post-type',
- 'from' => 'page',
- 'to' => 'post-type',
- 'sortable' => true,
- 'cardinality' => 'one-to-many',
- 'admin_box' => array(
- 'show' => 'from',
- 'context' => 'side'
- ),
- 'admin_column' => false,
- 'title' => __('Connected post types on page', 'domain')
- ) );
- // Show Admin Box for page-post-type connection only on homepage
- function restrict_p2p_box_display( $show, $ctype, $post ) {
- if ( 'page-post-type' == $ctype->name) {
- $frontpage_id = get_option('page_on_front');
- return($post->ID == $frontpage_id);
- }
- 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(
- 'post_type' => 'post-type',
- '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;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement