Connecting with other CPTs
-
I’d like to connect the locations post type with the product post type created by woocommerce using posts-to-posts.
I’ve been able to register a connection type using:
‘ /** Connecting Posts to Posts and Pages such as Locations to Shop Products. */
function my_connection_types() {
p2p_register_connection_type( array(
‘name’ => ‘locations_to_product’,
‘from’ => ‘location’,
‘to’ => ‘product’
) );
}
add_action( ‘p2p_init’, ‘my_connection_types’ ); ‘I then added this code to single-location.php:
‘ /* Connect a location to products */
$connected = new WP_Query( array(
‘connected_type’ => ‘locations_to_product’,
‘connected_items’ => get_queried_object()
) );echo ‘<p>Related products:</p>’;
echo ‘- ‘;
- ‘;
the_title();
echo ‘
while( $connected->have_posts() ) : $connected->the_post();
echo ‘‘;
endwhile;
echo ‘‘
;wp_reset_postdata(); ‘
The meta boxes are in place but for some reason they don’t work.Is there a problem with the code or am I adding it to the wrong page?
- ‘;
- The topic ‘Connecting with other CPTs’ is closed to new replies.