0

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

1

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; ?>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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