WordPress.org

Ready to get started?Download WordPress

Forums

Posts 2 Posts
Try to echo 2 relationships fields... (1 post)

  1. oscarasking
    Member
    Posted 4 months ago #

    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/

Reply

You must log in to post.

About this Plugin

About this Topic