Home › Forums › General Issues › Custom field not appearing in author.php
Hey!
Wondering if anyone could shed any light as to why none of the fields are showing on the author.php page when I try and call them as I conventionally would using
<?php the_field('profile_image');?>
Would really appreciate any thoughts.
Thanks
You need to supply the author ID in the format 'user_'.$author_id
$user_id = get_the_author_meta('ID');
the_field('profile_image', 'user_'.$user_id);
for more information http://www.advancedcustomfields.com/resources/how-to-get-values-from-a-user/
Thanks for that – it only seems to work for authors that have a post attributed. Do you know at all how to have them display for all authors regardless of having published posts?
Thanks again in advance!
This is an author.php page that I created for a site that uses an ACF image field and defaults to something else if an image has not been uploaded. It works for me whether or not the user has any published posts.
<?php
/*
The template for displaying Author Archive pages
*/
get_header();
$has_banner = apply_filters('ssi_page_has_banner', true);
do_action('ssi_page_banner');
?>
<div id="content-wrapper">
<div class="wrapper-inner">
<div id="content" itemscope itemtype="http://schema.org/Person" class="right-sidebar">
<div class="inner">
<?php
$user_id = get_the_author_meta('ID');
$user_image = false;
if (function_exists('get_field')) {
$attachment_id = get_field('user_options_author_photo', 'user_'.$user_id);
if ($attachment_id) {
$user_image = wp_get_attachment_image_src($attachment_id, 'author-photo');
}
} // end if function
if ($user_image) {
$user_image = '<img src="'.$user_image[0].'" width="'.
$user_image[1].'" height="'.$user_image[2].
'" alt="'.$user_name.'" />';
}
if (!$user_image) {
$user_name = get_the_author();
$user_email = get_the_author_meta('user_email');
$user_image = get_avatar($user_email, 300, NULL, $user_name);
}
?>
<div class="author-info">
<div class="author-image" itemprop="image">
<?php echo $user_image; ?>
</div>
<div class="author-description" itemprop="description">
<h1 itemprop="name"><?php echo get_the_author(); ?></h1>
<?php
$description = false;
if (function_exists('get_field')) {
$description = get_field('user_options_detailed_bio', 'user_'.$user_id);
} // end if function
if (!$description) {
$description = get_the_author_meta('description');
}
?>
<p itemprop="description"><?php echo $description; ?></p>
</div>
<div class="clearfix"></div>
<hr />
</div>
<?php
if (have_posts()) {
get_template_part('template-parts/block', 'article-archive');
} else {
// no posts
?>
<p>No results were found.</p>
<?php
}
?>
</div>
</div>
<div id="sidebar-after-content">
<div class="inner">
<?php get_sidebar('blog'); ?>
</div>
</div>
<div class="clearfix"></div>
</div>
</div>
<?php
get_footer();
?>
You must be logged in to reply to this topic.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
ACF wouldn’t be so widely used in WordPress if it didn’t have some pretty amazing capabilities. In this article, we look at a few of the features we’ll discuss during “7 things you didn’t know you could do with ACF” at #WPEDecode later this month. https://t.co/5lnsTxp81j pic.twitter.com/Yf0ThPG1QG
— Advanced Custom Fields (@wp_acf) March 16, 2023
© 2023 Advanced Custom Fields.
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.