CPT-onomies: Using Custom Post Types as Taxonomies
[resolved] Pull assigned custom post type meta dat (4 posts)

  1. anterys
    Posted 3 years ago #

    Hi Rachel,

    Once again, great plugin.

    Using your movies and actors scenario, I have custom meta attached to both (e.g., release date for movies and age for actors).

    I have a template page to list all movies. For each movie, I want to list the actors and their ages.

    How do I retrieve the post and custom meta information from an attached CPT-onomy while in the loop?



  2. Rachel Carden
    Plugin Author

    Posted 3 years ago #

    Here you go! Hope this helps!

    <?php if ( have_posts() ) : while ( have_posts() ) : the_post();
       ?><h2><?php the_title(); ?></h2><?php
       // retrieves the actors assigned to this movie
       $actors = wp_get_object_terms( get_the_ID(), 'actors' );
       if ( $actors ) {
             foreach( $actors as $actor ) {
                // if you wanted to retrieve the post info for each actor
                $actor_post = get_post( $actor->term_id );
                // retrieves the 'age' custom post meta
                $age = get_post_meta( $actor->term_id, 'age', true );
                ?><li><?php echo $actor->name; if( $age ) echo ' - ' . $age; ?></li><?php
    endwhile; endif; ?>
  3. anterys
    Posted 3 years ago #

    Thanks Rachel. This is what I was looking for. I ended up finding likely an equivalent way to do this using variations of the functions you have here, namely get_the_terms (in place of wp_get_object_terms) and get_post_custom (as opposed to get post meta). My guess is that both do the same.

  4. Rachel Carden
    Plugin Author

    Posted 3 years ago #

    Awesome. Glad you were able to get it working!

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic