I'm trying to get the author's avatar, first name and last name and their bio(description).
Luckily I found out how to do do just that, using several functions from the WordPress codex. What I'm trying to do now is get the current author of the post in my foreach
loop.
But what I noticed, I changed the author of a post I made myself earlier to someone else, but it did not change on the front end. It kept showing the original author and not the new modified one.
This is a part of my code just after the header:
<section class="page blog">
<div class="container">
<?php foreach($items as $item) { ?>
<div class="row">
<div class="col-md-7">
<div class="post-content">
<h3 class="post-title"><?php echo $item->post_title; ?></h3>
<?php echo str_replace('<p>', '<p class="post-content--alinea">', apply_filters('the_content', $item->post_content)); ?>
<p class="post-date-time">
<?php echo strftime('%A %d %B \'%y, %H:%M', strtotime($item->post_date)); ?>
</p>
</div>
<div class="post-author">
<div class="col-md-3">
<?php echo get_avatar(get_the_author_meta('ID'), 128, '', 'Profielfoto'); ?>
<p class="post-author--caption"><?php the_author_firstname(); echo ' '; the_author_lastname(); ?></p>
</div>
<div class="col-md-9">
<h3 class="post-author--bio-title">Let's meet!<?php /* the_author(); */ ?></h3>
<p class="post-author--bio"><?php the_author_meta('description'); ?></p>
</div>
</div>
</div>
I think I'm missing something in the foreach
loop. But I'm not sure what.
$item->post_author
shows the right author ID, now how to get it to show that name... and description.. – ALXvirtual Mar 11 '16 at 11:30get_the_author_meta
. If used within The Loop, the user ID need not be specified, it defaults to current post author. A user ID must be specified if used outside The Loop. ~ WordPress say. I hope you know what I mean The Loop, not foreach loop. So you need to get the author ID. ie;$author_id = get_post_field( 'post_author', $item->ID );
Sorry for late respons. yes you are right,. Then you can use get_the_author_meta( 'user_email', $author_id ), to get email. etc, – Jevuska Mar 11 '16 at 11:32