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

Posts-to-Posts troublshooting

By: FriendlyWP on Aug 17th, 2012  |  syntax: PHP  |  size: 2.27 KB  |  views: 35  |  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. // FUNCTIONS.PHP CODE
  2. add_action( 'wp_loaded', 'my_connection_types' );
  3. function my_connection_types() {
  4.         // Make sure the Posts 2 Posts plugin is active.
  5.         if ( !function_exists( 'p2p_register_connection_type' ) )
  6.                 return;
  7.  
  8.         p2p_register_connection_type( array(
  9.                 'name' => 'books_to_series',
  10.                 'from' => 'books',
  11.                 'to' => 'series'
  12.         ) );
  13.    
  14.     p2p_register_connection_type( array(
  15.                 'name' => 'excerpts_to_books',
  16.                 'from' => 'book_excerpt',
  17.                 'to' => 'books',
  18.         ) );
  19.    
  20.     p2p_register_connection_type( array(
  21.                 'name' => 'praise_to_books',
  22.                 'from' => 'book_praise',
  23.                 'to' => 'books',
  24.         ) );
  25. }
  26.  
  27. // TMPL-BOOKS.PHP CODE
  28. <?php
  29. $my_query = new WP_Query( array(
  30. 'post_type' => 'series',
  31. 'nopaging' => true,
  32. //'order' => 'ASC',
  33. //'orderby' => 'menu_order',
  34. ) );
  35.  
  36. p2p_type( 'books_to_series' )->each_connected( $my_query, array(), 'books' );
  37.  
  38. while ( $my_query->have_posts() ) : $my_query->the_post();
  39.  
  40. $current_series_id = get_the_ID();
  41. $current_series_content = get_the_content();
  42. ?>
  43.  
  44. <section class="post-content clearfix">
  45.  
  46. <h3 class="h2"><a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a></h3>
  47.  
  48. <?php
  49.         // Display connected books
  50.         foreach ( $post->books as $post ) : setup_postdata( $post );
  51.                
  52.                 // testing to see if anything displays at all in the foreach loop (it doesn't if running 1.4 but everything shows in 1.3.1):
  53.                 echo 'hello!';
  54.  
  55.         if (function_exists('vp_get_thumb_url')) {
  56.             $thumb=vp_get_thumb_url($post->post_content, 'medium');
  57.             if ($thumb!='') { ?>
  58.                 <a href="<?php the_permalink(); ?>"><img class="coverimg" src="<?php echo $thumb; ?>" alt="<?php the_title(); ?>" title="<?php the_title(); ?> by Sherri Browning Erwin" /></a>
  59.             <?php } else { ?>
  60.                 <div class="cover">
  61.                     <img src="<?php echo $url; ?>/wp-content/uploads/no-cover.png" alt="<?php the_title(); ?>" title="<?php the_title(); ?> by Sherri Browning Erwin" />
  62.                 </div><!-- .cover -->
  63.             <?php }
  64.         }
  65.  
  66.         endforeach;
  67.  
  68.         if($current_series_content !== "") { ?>
  69.         <div class="series-desc"><?php echo $current_series_content; ?></div><!-- .series-desc -->
  70. <?php }
  71.         wp_reset_postdata();
  72.  
  73. ?>
clone this paste RAW Paste Data