• I have two custom post types: groups and videos. I’m displaying all posts in “groups” as a list within my header:

    <?php $loop = new WP_Query( array( 'post_type' => 'groups') ); ?>
    <?php while ( $loop->have_posts() ) : $loop->the_post(); ?>
      <ul>
        <?php the_title( '<li><h2 class="entry-title"><a id="' . the_title_attribute( 'echo=0' ) . '" rel="bookmark">', '</a></h2></li>' ); ?>
      </ul>
    <?php endwhile; ?>

    Now I connected the posts from “videos” to my posts in “groups” using the posts 2 posts plugin. E.g. i have a post called “skateboard clip” in “videos” and I connected it to the post “Sport” in “groups”. If I now click on “Sport” in the header, I want to load all connected posts to it in my content div. I tried this, but it doesn’t quite work… here’s my code from the content div:

    <?php $loop = new WP_Query( array(
    'connected_type' => 'posts_to_posts',
    'connected_items' => get_queried_object_id(),
    'nopaging' => true
    ) );
    
    ?>
    
    <?php while ( $loop->have_posts() ) : $loop->the_post(); ?>
      <ul>
        <?php the_title( '<li><h2 class="entry-title"><a id="' . the_title_attribute( 'echo=0' ) . '" rel="bookmark">', '</a></h2></li>' ); ?>
      </ul>
    <?php endwhile; ?>

    How can I – after clicking on the different posts in the header – display the connected posts?

    https://www.ads-software.com/plugins/posts-to-posts/

  • The topic ‘Display posts that are conntected to posts’ is closed to new replies.