WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm fairly new to wordpress but trying to get recent posts by a specific author. The following code displays only most recent bog posts. I am using a custom field to get the author ID.

EDIT by vancoder: By which I mean, I am using the ACF plugin, which allows the selection of 1 or more WP users, the api returns the selected user objects

Any suggestions would be amazing ...

<?php $current_user = get_field('username');
if( $current_user ) : ?>
<div id="related-posts">
    <h3 class="divider-header"><span>Knowledge Community Articles</span></h3>
    <?php $userID = $current_user->ID;
    $args = array(
    'author' => $userID,
    'showposts' => 2,
    'caller_get_posts' => 1

    $query = new WP_Query($args);
    if( $query->have_posts() ) {
    while ($query->have_posts()) : $query->the_post(); ?>
        <div class="article-excerpt<?php echo ' excerpt-' . $c; ?>">
            <h4><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h4>
                <div class="post-meta">
                <div class="post-author">By <a href="<?php echo get_author_posts_url(get_the_author_meta( 'ID' )); ?>"><?php the_author_meta('display_name'); ?></a></div>
                </div><!-- .post-meta -->
            <?php the_excerpt(); ?>
        </div><!-- .article-excerpt -->
        <?php endwhile; } ?>
        <a href="<?php echo get_author_posts_url(get_the_author_meta( 'ID' )); ?>">More from this Contributor &rarr;</a>
        </div><!-- #related-posts -->
<?php endif; ?>
share|improve this question
What is the exact value of $current_user? – toscho Apr 30 '13 at 22:27
Are you just getting posts for any particular author that has been queried? couldn't you just copy twentytwelve's author.php and alter as needed? – NW Tech Apr 30 '13 at 22:44
I have edited the question to explain the custom field / $current_user stuff. – vancoder Apr 30 '13 at 23:21
What is the value of $current_user->ID? – vancoder Apr 30 '13 at 23:25
Thanks vancoder. That's correct. 'username' is the custom field used to input the user id. So $current _user is whichever user ID i input. Just trying to set up profile pages for individual authors that display their latest posts. Hope that explains it. Thanks for the help. Ill take a look at author.php – pwd3zz May 1 '13 at 2:21

Your Answer


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

Browse other questions tagged or ask your own question.