WordPress.org

Ready to get started?Download WordPress

Forums

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

  1. anterys
    Member
    Posted 1 year 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?

    Thanks!

    http://wordpress.org/extend/plugins/cpt-onomies/

  2. Rachel Carden
    Member
    Plugin Author

    Posted 1 year 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 ) {
          ?><ul><?php
             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
    
             }
          ?></ul><?php
       }
    
       the_content();
    
    endwhile; endif; ?>
  3. anterys
    Member
    Posted 1 year 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
    Member
    Plugin Author

    Posted 1 year 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