WordPress.org

Ready to get started?Download WordPress

Forums

Posts 2 Posts
[resolved] Get connected posts of connected posts (7 posts)

  1. Aurélien Denis
    Member
    Posted 2 years ago #

    Hi,

    after reading the documentation, I can't find to solve this problem :

    "how can I show connected posts of a connected posts of my current post".

    Yes, I know it's a bit strange. Let me explain in more details. I have custom post type for Hotel. Golfs are connected to Hotels. And Golfs-Courses are connected to Golfs.

    My goal is to show Golfs-Courses in the loop of my connected Golfs which appeared in the Hotel page (single-hotel.php).

    I tried something like this in the single-hotel.php file : http://pastebin.com/CzciExmJ

    If someone could help me, it would be awesome! Thanks.

    http://wordpress.org/extend/plugins/posts-to-posts/

  2. scribu
    Member
    Plugin Author

    Posted 2 years ago #

    Replace this:

    <?php $related = p2p_type( 'golfs_courses' )->get_related( get_queried_object_id() ); ?>

    with this:

    $related = new WP_Query( array(
      'connected_type' => 'golfs_courses',
      'connected_items' => $post->ID,
      'nopaging' => true,
    ) );

    And then you have to do something with $related. For example:

    while ( $related->have_posts() ) : $related->the_post();
    
    ...
    
    endwhile;
  3. Aurélien Denis
    Member
    Posted 2 years ago #

    Awesome support for an awesome plugin... what else ? :)

  4. scribu
    Member
    Plugin Author

    Posted 2 years ago #

    I'm not sure what you mean. Were you expecting a free beverage as well? :P

  5. Aurélien Denis
    Member
    Posted 2 years ago #

    ^^

    I'll be happy to offer it you if you come in France - for WordCamp for example. ;)

  6. Aurélien Denis
    Member
    Posted 2 years ago #

    Hi Scribu,

    another question related to the previous lines of code.

    After the endwhile; I'd like to insert

    <?php comments_template(); ?>

    But nothing shows... any idea?

  7. scribu
    Member
    Plugin Author

    Posted 2 years ago #

    I assume you have to call setup_postdata( $appropriate_post_object ); before that.

    PS: This is getting offtopic.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic