Want more features on Pastebin? Sign Up, it's FREE!

Display Posts 2 Posts Admin metabox only on specific page ID

By: Twansparant on Jun 7th, 2012  |  syntax: PHP  |  size: 1.06 KB  |  views: 110  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  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;
clone this paste RAW Paste Data