I have a page that queries a custom post type called "Clients" that is organized by a taxonomy called "Industry Type." As an example, see the code below:
<h2>Automotive</h2>
<ul>
<?php
//Target The Client CPT & Taxonomy
$auto_args = array(
'post_type' => 'client',
'order_by' => 'title',
'order' => 'ASC',
'posts_per_page' => '-1',
'tax_query' => array(
array(
'taxonomy' => 'industry-type',
'field' => 'slug',
'terms' => 'automotive'
)
)
);
//Setup The Query
$auto_query = new WP_Query($auto_args);
//The Loop
while($auto_query->have_posts()) : $auto_query->the_post();
?>
<li>
<?php the_title(); ?>
</li>
<?php endwhile; wp_reset_query(); ?>
</ul>
<h2>Beauty/Fashion</h2>
<ul>
<?php
//Target The Client CPT & Taxonomy
$beauty_args = array(
'post_type' => 'client',
'order_by' => 'title',
'order' => 'ASC',
'posts_per_page' => '-1',
'tax_query' => array(
array(
'taxonomy' => 'industry-type',
'field' => 'slug',
'terms' => 'beauty-fashion'
)
)
);
//Setup The Query
$beauty_query = new WP_Query($beauty_args);
//The Loop
while($beauty_query->have_posts()) : $beauty_query->the_post();
?>
<li><?php the_title(); ?></li>
<?php endwhile; wp_reset_query(); ?>
</ul>
What I am trying to accomplish with Posts2Posts is check to see if any of the list items pulled from the query have a connection. Within WP, I have a connection in place between clients and case studies. If a client has a case study connected to it, I would like to add a submenu to that list item like so:
<li>
<?php the_title(); ?>
<ul class="connected">
<li>Connected Case Study</li>
</ul>
</li>
Truth be told, I am a bit vexed as to how to accomplish this, but I tried the following code from the basic usage tutorial with no luck:
<h2>Technology</h2>
<ul>
<?php
//Target The Client CPT & Taxonomy
$technology_args = array(
'post_type' => 'client',
'order_by' => 'title',
'order' => 'ASC',
'posts_per_page' => '-1',
'tax_query' => array(
array(
'taxonomy' => 'industry-type',
'field' => 'slug',
'terms' => 'technology'
)
)
);
//Setup The Query
$technology_query = new WP_Query($technology_args);
//Check to see if there is a relationship between a client and a case study
p2p_type( 'clients_to_case_studies' )->each_connected( $wp_query );
//The Loop
while($technology_query->have_posts()) : $technology_query->the_post();
?>
<?php if($connected->have_posts()) { ?>
<li>
<?php the_title(); ?>
<ul class="connected">
<li>Testing...</li>
</ul>
</li>
<?php } else { ?>
<li><?php the_title(); ?></li>
<?php }
endwhile; wp_reset_query(); ?>
</ul>
This code just outputs a blank:
<ul></ul>
Any chance I could be pushed in the right direction. Or, a bit of info as to if this is even possible