I have a CPT with slug of ‘teammember’ that is being converted to taxonomy by CPT-onomies plugin and attached to another CPT ‘event’. The CPT ‘teammember’ has an image custom field ‘headshot’. I am using a post data custom field called ‘special’ on a page to allow the author to pick an ‘event’ to display on this page. Along with custom fields from the chosen ‘event’, I want to include the ‘headshot’ from the chosen ‘teammember ‘ of that ‘event’. I can not seem to make this work. I can get regular term data from the selected ‘teammember’ like title, but not a custom field.
Below is a simplified version of the code I am trying…
$post_object = get_field('special');
if( $post_object ):
$post = $post_object;
setup_postdata( $post );
if ( $team_members = wp_get_post_terms( $post->ID, 'teammember' ) )
$author = $team_members;
$permalink = get_permalink( $author->term_id );
print '<a href="' . $permalink . '">' . $author->name . '</a>';
<?php $image = get_field('headshot'); ?>
<a href="<?php the_permalink(); ?>">
<img src="<?php echo $image['url']; ?>" alt="<?php echo $image['alt']; ?>">
<?php the_title(); ?>, <?php the_date(); wp_reset_postdata(); ?>
Any ideas or guidance is appreciated -thanks!
CPT-onomies has a weird structure as it forces a post as a taxonomy. To get the custom field, you need to pass the id of this post (the post that is converted to a taxonomy) as the second parameter. Something like this:
<?php $image = get_field('headshot', $cptonomies_post_id); ?>
where $cptonomies_post_id is the id of the post.
I hope this makes sense.