User field on custom post type
-
I have created a custom post type for ‘stars’. These are star employees so the cms admin needs to click on stars and choose a member of staff and write a bit about why they are a star.
I have create a field type of User Field and called in ‘star_user_info’. This is the drop down that displays all the users (employees). I can see this all working nicely under my Stars post type.
However I am struggling with the correct template tags to show the persons name they have selects and their avatar.
Here is my code… (feels like i should have user->display_name in there somewhere!?)
<?php $query = new WP_Query( array( ‘post_type’ => ‘stars’ ) );
if ( $query->have_posts() ) : ?>
<?php while ( $query->have_posts() ) : $query->the_post(); ?><?php
$author_id = get_the_author_meta(‘ID’);
$star = the_field(‘star_user_info’, ‘user_’. $author_id );
$nominated = the_field(‘nominated_by’, ‘user_’. $author_id );
?><article class=”entry borderbot”>
<h3 class=”title”>Why <?php echo $star ;?> is a star</h3>
<p><?php the_content(); ?></p>- <label>Company value: </label><?php echo the_field(“company_value”); ?>
- <label>Nominated by: </label><?php echo $nominated ; ?>
</article>
<?php endwhile; wp_reset_postdata(); ?><?php else : ?>
<?php endif; ?>
https://www.ads-software.com/plugins/advanced-custom-fields/
- The topic ‘User field on custom post type’ is closed to new replies.