Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I am developing an author badge for my Wordpress site and I am learning how to call meta functions (needs to be within The Loop). The meta functions that I am calling are author bio related, like username, last name etc

Here is a code example:

<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>

    About <?php the_author(); ?>, the author of this blog
    <?php userphoto_the_author_thumbnail() ?>
    <?php get_the_author_meta( 'description' ); ?>

<?php endwhile; else: ?>
<p><?php _e('Sorry, no posts matched your criteria.'); ?></p>
<?php endif; ?>

I added this example to my author.php file and it worked, however it displayed the same thing multiple times (hence the loop). How do I actually do this if I want to call meta functions in Wordpress and not have them echoed multiple times like this?

I am certain that I am doing this incorrectly and there is a correct way of achieving it.

If you choose to reply, please be detailed as my knowledge of PHP coding is to the extend that I learned what echo is today.

share|improve this question
add comment

1 Answer

up vote 0 down vote accepted

Add your author meta information after if ( have_posts() ) :

    <?php if ( have_posts() ) : the_post(); ?>

    About <?php the_author(); ?>, the author of this blog
    <?php userphoto_the_author_thumbnail() ?>
    <?php echo get_the_author_meta( 'description' ); ?>

<?php rewind_posts();

while ( have_posts() ) : the_post(); ?>

<?php //loop stuff  ?>

<?php endwhile; else: ?>
<p><?php _e('Sorry, no posts matched your criteria.'); ?></p>
<?php endif; ?>
share|improve this answer
    
I copy and pasted your code into my author.php and it didn't return with the called meta functions. Are you sure that you wrote that correctly? –  Amanda Bynes Aug 22 '12 at 18:11
    
I forgot to add the_post(); to queue up the first post. –  Chris_O Aug 22 '12 at 18:50
    
Thank you that worked perfectly, I have just one question before I accept this as correct. Is there any better way of doing this or is this the best practice to accomplish what I am trying to do? –  Amanda Bynes Aug 22 '12 at 19:00
    
If you want to get the author stuff outside the loop you can assign a $variable = get_queried_object(); then use $varibale->display_name, $variable->description; instead but the code I used in the answer is they way the twentytwelve theme does it so I would say it's "best practices" –  Chris_O Aug 23 '12 at 16:36
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.