Home › Forums › General Issues › Custom field not appearing in author.php › Reply To: Custom field not appearing in author.php
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();
?>
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!
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 Privacy Policy. If you continue to use this site, you consent to our use of cookies.