Support » Plugin: Posts 2 Posts » [Plugin: Posts 2 Posts] Ordering/ displaying via taxonomy term?

  • Hi there,
    I love this plugin- it is so useful for what I’m trying to do. Thank you!

    I have two issues which I’ll separate into different posts.

    Firstly, I’ve managed to connect posts and display them- it’s all fabulous. I now want to sort and display my associated resources for the user by a Taxonomy.

    The connected posts displayed on the CPT page ‘Training Modules’ are a CPT called ‘Associated Resources’ which has a taxonomy attached to it called ‘File Types’- registered using the Ultimate Taxonomy Manager plugin. The user selects file types such as ‘Document- handout’, ‘Document-slide’, ‘Video’ etc…

    I want to cluster the Associated Resources by file type (taxonomy term name) in a list below the post. I have the list- which looks great, but I’m not sure how to sort them so all videos are together, all documents are together, etc…

    This is what I have now:

    // Find connected pages
    $connected = new WP_Query( array(
      'connected_type' => 'resources_to_training_module',
      'connected_items' => get_queried_object_id(),
    ) );
    // Display connected pages
    if ( $connected->have_posts() ) :
    <?php while ( $connected->have_posts() ) : $connected->the_post(); ?>
    	<tr style="vertical-align: middle; font-size: 0.7em;"><td>
    	<a href="<?php the_field('link'); ?>"><img src="<?php echo do_shortcode( '[xy_file_types field="file_type_icon"]' ) ?>" width="40" height="40" /></a></br>
    	<a href="<?php the_field('link'); ?>"> Download </a>
    	<td><strong><?php the_title(); ?></strong><br/><?php the_field('description'); ?></td>
    	<td class="post_entry_comment_option">			<div class="comments-link">
    				<?php comments_popup_link( '<span class="leave-reply">' . __( 'Reply', 'twentyeleven' ) . '</span>', _x( '1', 'comments number', 'twentyeleven' ), _x( '%', 'comments number', 'twentyeleven' ) ); ?>
    			</div><br/>			<div class="comments-more"><a href="<?php the_permalink(); ?>"> More...</a></div></td></tr>
    <?php endwhile; ?>

Viewing 1 replies (of 1 total)
  • It may not be the most elegant or peformance-optimized method, but as a last resort you could run several queries, one after the other, each targetting a specific taxonomy.

    Something like this:

    $connected_custom = new WP_Query( array(
      'connected_type' => 'stuff_to_posts',
      'connected_items' => get_queried_object_id(),
      'post_type' => 'my_freaking_post_type',
      'orderby' => 'date',
      'order' => 'ASC',
      'tax_query' => array(
          'taxonomy' => 'my_taxonomy',
          'field' => 'slug',
          'terms' => 'my_term',
          //'operator' => 'NOT IN'
    ) );
Viewing 1 replies (of 1 total)
  • The topic ‘[Plugin: Posts 2 Posts] Ordering/ displaying via taxonomy term?’ is closed to new replies.