views:

22

answers:

0

I have a simple function:

$connected_posts_ids = p2p_get_connected('to', get_the_ID(), 'actor');

This returns:

Array ( [0] => 78 ) 

Long story short, it basically tells me the post_id of a post that is related to the post being viewed. It is an array because I can have multiple related posts to the given post.

What I am trying to do

This deals with custom post_types on a single.php page.

Put simply, I want to create a new query loop using the post_id returned from $connected_posts_ids so that I can grab the title, content, of the related post.

Here is what I have been trying but it does not work. Best guess is because it's being called on a single.php page that already has a loop, but I can't figure out how to turn it into a new query that works.

$connected_posts_ids = p2p_get_connected('from', get_the_ID(), 'musicians');

print_r($connected_posts_ids); query_posts(array('post__in' => $connected_posts_ids)); while ( have_posts() ) : the_post(); echo get_post_meta(get_the_ID(), 'musiciansimage', true); the_title(); endwhile; wp_reset_query();

The above returns nothing for me.

Here is a snippet of code that kind of works, but is not at all what I need. It just happens to return the values I am looking for, so I know my post_id is correct:

<?php

$connected_posts_ids = p2p_get_connected('from', get_the_ID(), 'musicians'); $post_id = 79; $queried_post = get_post($post_id); ?>

post_title; ?>

post_content; ?>

I've even tried the following, which seems that it should work but does not:

<?php 

$connected_posts_ids = p2p_get_connected('from', get_the_ID(), 'musicians'); $myposts = new WP_Query( array('post__in' => $connected_posts_ids )); print_r($myposts); ?>

    have_posts() ) : $myposts->the_post(); ?>
  • " title="">

Really could use some help as I am out of ideas now.

thanks