Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have two custom post types called actors and movies. In movies, I have a custom meta box that got data from actors post type.

When an actor is selected in movie post, the values (post_id, meta_key and meta_values) are stored in postmeta table.

So I build a page to show all movie info. Fot that, I'm using WP_Query:

     <?php
        $args_movie = array('post_type' => 'movie','posts_per_page' => -1);
        $movie_posts = new WP_Query($args_movie);

        if($movie_posts->have_posts()) : 
           while($movie_posts->have_posts()) : 
           $movie_posts->the_post();
     ?>

        <h2><?php the_title() ?></h2>

     <?php endwhile; else: ?>
        Oops, there are no posts.
     <?php endif; ?>

This works fine for me. Now I'm trying to show all actors associated with each movie. This script return an array of IDs:

$actors= get_post_meta( get_the_ID(), 'actors'); print_r($actors); 

But how can I using this array to get actor's titles?

SOLVED

$args = array('post_type' => 'actors','orderby' => 'ASC','post__in' => $areas);

more info

share|improve this question
add comment

1 Answer

You can make use of ids in $actor the following way to get the actor's title.

$args = array(
    'post_type' => 'actors',
    'post__in'  => $actors,
);

$actors_posts = new WP_Query( $args );

if( $actors_posts->have_posts() ) :
    while( $actors_posts->have_posts() ) : 
        $actors_posts->the_post();
    ?>
        <h2><?php the_title() ?></h2>
    <?php endwhile; else: ?>
        echo 'Oops, there are no posts.';
<?php endif; ?>
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.