Posts2Posts and Customs posts with Custom taxonomies
-
Hello – I’m a WP newby and I try to extend the connection between a custom post type (“cpt_profiles”) and the regular WP posts.
The scenario:
the idea is to connect a post dedicated to products reviews to the profile of the brand/company. This is the function I use:
function product2profile() { p2p_register_connection_type( array( 'name' => 'product_to_profile', 'from' => 'post', 'reciprocal' => true, 'to' => 'cpt_profiles' ) ); } add_action( 'p2p_init', 'product2profile' );
And in the template file I’ve created the WP_query:
<?php // Find connected pages $connected = new WP_Query( array( 'connected_type' => 'product_to_profile', 'connected_items' => get_queried_object(), 'nopaging' => true, ) );
Then I retrieve the data I need in the loop
if ( $connected->have_posts() ) : while ( $connected->have_posts() ) : $connected->the_post(); echo get_the_title(); //other fields... endwhile; // Prevent weirdness wp_reset_postdata(); endif;
And that’s working great: what I got is the name and other info (the website link) that appear at the bottom of the product post. And that’s fine.
Now:
The custom post type (“cpt_profiles”) have also custom taxonomies (“type”), that I used to classify the profile (e.g. “Manufacturer”, “Distributor”, “Association” etc…)
What I’d like to achieve is that when a product have ALSO a profile with “Distributor” tax assigned, I’d like also to display the name/info of the distributor, like follow:
Info: <name-manufacturer>
Distributor: <name-distributor>Is that possible? Sorry for this long thread…
- The topic ‘Posts2Posts and Customs posts with Custom taxonomies’ is closed to new replies.