0

I'm working on a multi-author blog, and I'm trying to produce an authors list with recent posts like this page (site is drupal): http://www.internationalrivers.org/blogs

I'm working on a draft here: http://nape.kevinmgibbons.com/authors

I want to exclude admin, ira, and ivan (users 1,3,4).

Here is the code I've pieced together:

    <?php
    $authors = $wpdb->get_results('SELECT DISTINCT post_author FROM '.$wpdb->posts);
    if($authors):
    foreach($authors as $author):   
?>

<div class="row authorentry">

<div class="col-lg-2">
    <?php if(get_the_author_meta('description', $author->post_author)): ?>
        <div class='blog-avatar'>
            <?php echo get_avatar(get_the_author_meta('user_email', $author->post_author), 80); ?>
        </div>
    <?php endif; ?>
</div><!-- /.col-lg-2 -->

<div class="col-lg-4 descriptionblock">
    <div class='author' id='author-<?php the_author_meta('user_login', $author->post_author); ?>'>
        <h3 class="blogbyauthor"><?php the_author_meta('display_name', $author->post_author); ?></h3>


    <?php if(get_the_author_meta('description', $author->post_author)): ?>
        <div class='description'>
            <p class="blogbyauthor"><?php the_author_meta('description', $author->post_author); ?></p>
        </div><!-- /.description -->
    </div><!-- /.author -->
</div><!-- /.col-lg-4 -->

<?php endif; ?>

<?php
    $recentPost = new WP_Query('author='.$author->post_author.'&showposts=4');
    while($recentPost->have_posts()): $recentPost->the_post();
?>

<div class="col-lg-6">
<ul class="blogbyauthor">
    <li class="blogbyauthor" id="post-<?php the_ID(); ?>">
        <a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>
         <?php the_time('F jS, Y') ?>
    </li>
</ul>
</div><!-- /.col-lg-6 -->

<?php endwhile; ?>

<?php if(get_the_author_meta('twitter', $author->post_author) || get_the_author_meta('facebook', $author->post_author) || get_the_author_meta('linkedin', $author->post_author) || get_the_author_meta('digg', $author->post_author) || get_the_author_meta('flickr', $author->post_author)): ?>
<?php endif; ?>

</div><!-- /.row -->

<hr>

<?php endforeach; endif; ?>

Two questions:

  1. How can I exclude users 1,3,4? I've tried a lot of methods from other posts.
  2. Is there a better/cleaner way to do what I'm trying to do?

I'm a bit of a newb when it comes to Wordpress PHP, so I appreciate any help you can give.

1

You could try the following SQL query:

"SELECT DISTINCT post_author FROM $wpdb->posts WHERE post_author NOT IN (1,3,4)"

to exclude authors 1,3 and 4.

In general it would be more handy to retrieve the user ids automatically, so you wouldn't need to update your SQL query every time you want to exclude someone.

You could for example use the user meta to label those users that you want to exclude.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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