Exclude Author by ID

时间:2012-10-03 作者:Phantasmix

如何从中排除按ID列出的作者:

<?php
//displays all users with their avatar and their posts (titles)
$blogusers = get_users_of_blog();
if ($blogusers) {
  foreach ($blogusers as $bloguser) {
    echo \'<div class="content-slider-body">\';
    $user = get_userdata($bloguser->user_id);
    echo \'<div class="grid col-140">\' . get_avatar( $user->ID, 128 ) . \'</div>\';
    $args=array(
      \'author\' => $user->ID,
      \'post_type\' => \'post\',
      \'post_status\' => \'publish\',
      \'posts_per_page\' => 1,
      \'caller_get_posts\'=> 1
    );
    $my_query = null;
    $my_query = new WP_Query($args);
    if( $my_query->have_posts() ) {
      //echo \'List of Posts for \' . user->user_firstname . \' \' . $user->user_lastname;
      while ($my_query->have_posts()) : $my_query->the_post(); ?>

1 个回复
最合适的回答,由SO网友:Tom J Nowell 整理而成

哪里$that_user_your_filtering_out 是您不想过滤掉的用户/作者ID,请对循环进行此修改

foreach ($blogusers as $bloguser) {
    // modification starts here
    if($bloguser->user_id == $that_user_your_filtering_out){
        continue;
    }
    // modification ends here
    echo \'<div class="content-slider-body">\';
    $user = get_userdata($bloguser->user_id);

结束

相关推荐

Author.php不显示POST类型的帖子

我注意到,第211个主题的作者。php模板只显示普通帖子中的帖子,自定义帖子类型的帖子不显示在此模板中。如何查询作者的所有帖子,而不管帖子类型如何?我试过了global $wp_query; $theauthorid = get_current_user_id( ); query_posts( \'author=\' . $theauthorid ); 但它也不显示post类型post。有什么线索吗?