vendredi 28 novembre 2014

posts-2-posts: Basic Connection Problem


I have 3 Custom Post Types (CPTs)


The CPTs:



  1. Attorney CPT

  2. Practice Groups CPT (i.e. General Business, Maritime, etc)

  3. Areas of Concentration CPT (i.e. Litigation, Toxic Torts, etc.)


The Connections:




  1. Each attorney practices in 1 or more Areas of Concentration and so uses p2p to connect Attorneys to Areas of Concentration (atty_to_aoc).




  2. Each Area of Concentration belongs in 1 of 4 Practice Groups and so uses p2p to connect Areas of Concentration to Practice Group (aoc_to_practice_group).




The Problem:



  1. On attorney-single.php, I'm trying to display a list of all the Practice Groups to which an attorney belongs.

  2. However there is no connection between Attorney and Practice Group CPTs, only between Areas of Concentration and Practice Groups (aoc_to_practice_group).

  3. So I am trying (without success) to find a way to get the practice groups to show on attorney-single.php

  4. The code below (incorrectly) shows the Areas of Concentration not the (desired) Practice Groups.


The Code:



function displayAttyPracticeGroup(){

// Add multiple connections
$connected_type = array('aoc_to_practice_group', 'atty_to_aoc');
// Find connected pages
$new_query = new WP_Query( array(
'connected_type' => $connected_type,
'connected_items' => get_queried_object_id(),
'nopaging' => true,
'post_type' => array('practice'),
) );

if ( $new_query->have_posts() ) : ?>
<ul class="list-unstyled">
<li><strong>Practice Groups</strong></li>
<?php while ( $new_query->have_posts() ) : $new_query->the_post(); ?>
<li><?php echo get_the_title(); ?></li>
<?php endwhile; ?>
<?php endif; ?>
</ul>
<?php
wp_reset_postdata();
}




Aucun commentaire:

Enregistrer un commentaire