anterys
Member
Posted 9 months 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/
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; ?>
anterys
Member
Posted 9 months 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.
Awesome. Glad you were able to get it working!