Support

Account

Home Forums General Issues Custom field not appearing in author.php

Solved

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/

  • Worked perfectly – thanks!

  • 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();
    
    ?>
    
Viewing 5 posts - 1 through 5 (of 5 total)

The topic ‘Custom field not appearing in author.php’ is closed to new replies.