Title: Try to echo 2 relationships fields&#8230;
Last modified: August 21, 2016

---

# Try to echo 2 relationships fields…

 *  [oscarasking](https://wordpress.org/support/users/oscarasking/)
 * (@oscarasking)
 * [12 years, 1 month ago](https://wordpress.org/support/topic/try-to-echo-2-relationships-fields/)
 * Hello, can you help me?
 * I have three taxonomies in my blog (days, activities, hotels). These three taxonomies
   behave as follows:
 * – One day can have several activities in different hotels
    – An activity can 
   be held at a hotel on different days – A hotel can arrange different activities
   on different days
 * What I want is to print a listing as follows:
 * > Day # 1
   >  activity hotel schedule —- activity hotel schedule — …
   > Day # 2
   >  activity hotel schedule — …
 * I have this code to register de connections:
 *     ```
       p2p_register_connection_type( array(
         'name' => 'hoteles_to_actividades', //hotels_to_activities
         'from' => 'hotel', //hotel
         'to' => 'actividad' //activity
       ) );
   
       p2p_register_connection_type( array(
         'name' => 'dias_to_actividades', //days_to_activities
         'from' => 'dia', //day
         'to' => 'actividad', //activity
         'fields' => array(
           'horario' => array( //schedule
             'title' => 'Horario', //Schedule
             'type' => 'text',
           ),
         )
       ) );
       ```
   
 * And this other code to try to print the listing…
 *     ```
       query_posts('post_type=dia&posts_per_page=-1&order=DESC'); //day
       if ( have_posts() ) :
         while ( have_posts() ) : the_post();
           the_title();
   
           $connected = new WP_Query( array(
             'connected_type' => 'dias_to_actividades', //days_to_activities
             'connected_items' => get_queried_object(),
             'nopaging' => true,
             'connected_orderby' => 'title',
             'connected_order' => 'desc'
           ) );
           if ( $connected->have_posts() ) :
             while ( $connected->have_posts() ) : $connected->the_post();
               echo $post->post_title . '<br />';
             endwhile;
             wp_reset_postdata();
           endif;
         endwhile;
       endif;
       wp_reset_query();
       ```
   
 * My result with this code is almost nothing…
 * > Day #1
   >  Day #2 Day #3 …
 * Can anybody help me?
    Thanks in advance !!
 * [https://wordpress.org/plugins/posts-to-posts/](https://wordpress.org/plugins/posts-to-posts/)

Viewing 1 replies (of 1 total)

 *  [clariner](https://wordpress.org/support/users/clariner/)
 * (@clariner)
 * [11 years, 8 months ago](https://wordpress.org/support/topic/try-to-echo-2-relationships-fields/#post-4753395)
 * Your code is doing what it should be doing.
 * Where you have $post->post_title you the need to get the post information about
   schedule etc.
 * Have a look here [https://github.com/scribu/wp-posts-to-posts/wiki/Connection-metadata](https://github.com/scribu/wp-posts-to-posts/wiki/Connection-metadata)

Viewing 1 replies (of 1 total)

The topic ‘Try to echo 2 relationships fields…’ is closed to new replies.

 * ![](https://s.w.org/plugins/geopattern-icon/posts-to-posts_7a8e9d.svg)
 * [Posts 2 Posts](https://wordpress.org/plugins/posts-to-posts/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/posts-to-posts/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/posts-to-posts/)
 * [Active Topics](https://wordpress.org/support/plugin/posts-to-posts/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/posts-to-posts/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/posts-to-posts/reviews/)

## Tags

 * [p2p](https://wordpress.org/support/topic-tag/p2p/)

 * 1 reply
 * 2 participants
 * Last reply from: [clariner](https://wordpress.org/support/users/clariner/)
 * Last activity: [11 years, 8 months ago](https://wordpress.org/support/topic/try-to-echo-2-relationships-fields/#post-4753395)
 * Status: not resolved