Advertisement
FriendlyWP

Posts-to-Posts / Listing items with connetctions

Feb 17th, 2013
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.98 KB | None | 0 0
  1. <?php
  2. function show_directory() {
  3.     $args = array(
  4.             'post_status' => 'publish',
  5.             'orderby' => 'meta_value',
  6.             'order' => 'asc',
  7.             'posts_per_page' => -1,
  8.             'nopaging' => true,
  9.             'suppress_filters' => false,
  10.             'connected_type' => 'directory_to_projects',
  11.             'connected_direction' => 'to',
  12.             'connected_items' => 'any',
  13.         );
  14.     $dir_query = new WP_Query($args);
  15.  
  16.     if ($dir_query->have_posts()) : while ($dir_query->have_posts()) : $dir_query->the_post();
  17.     global $post;
  18.  
  19.         the_title();
  20.  
  21.        p2p_type( 'directory_to_projects' )->each_connected( $dir_query );
  22.              echo '<ul>';
  23.              foreach ( $post->connected as $post ) : setup_postdata( $post ); ?>
  24.                   <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
  25.  
  26.       <?php
  27.             endforeach;
  28.             echo '</ul>';
  29.       wp_reset_postdata();
  30.  
  31. endwhile;
  32. endif;
  33. }
  34. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement