Advertisement
Twansparant

Display Posts 2 Posts Admin metabox only on specific page ID

Jun 7th, 2012
264
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.06 KB | None | 0 0
  1. // Define page-post-type connection
  2. p2p_register_connection_type( array(
  3.     'id' => 'page-post-type',
  4.     'from' => 'page',
  5.     'to' => 'post-type',
  6.     'cardinality' => 'one-to-many',
  7.     'admin_box' => array('show' => 'from', 'context' => 'side')
  8. ) );
  9.  
  10. // Show Admin Box for page-post-type connection only on page with id 14
  11. function restrict_p2p_box_display( $show, $ctype, $post ) {
  12.     if ( 'page-post-type' == $ctype->name) {
  13.         return($post->ID == 14);
  14.     }
  15.     return $show;
  16. }
  17. add_filter( 'p2p_admin_box_show', 'restrict_p2p_box_display', 10, 3 );
  18.  
  19.  
  20. // Show page-post-type connections in homepage template
  21. if ( is_front_page() ) :               
  22.     if (function_exists('p2p_type')) {
  23.         $connected = new WP_Query( array(
  24.             'connected_type' => 'page-post-type',
  25.             'connected_items' => get_queried_object(),
  26.             'nopaging' => true
  27.         ) );
  28.         if ($connected->have_posts() ) :
  29.             while ($connected->have_posts() ) : $connected->the_post();
  30.                 the_title();
  31.             endwhile;
  32.         endif;
  33.         wp_reset_postdata();
  34.         wp_reset_query();
  35.     } else {
  36.         echo 'Plugin not found';
  37.     }
  38. endif;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement