通常情况下WP_User_Query
获取用户(/作者)。但正如我所读到的,您希望所有作者都来自当前页面循环帖子,因此可能更容易自己连接到循环中并收集它。
<?php
namespace WPSE109876;
/** Plugin Name: WPSE (#109876) Collect Author IDs */
defined( \'ABSPATH\' ) OR exit;
\\add_action( \'loop_start\', array( __NAMESPACE__.\'\\LoopCollector\', \'init\' ) )
class LoopCollector
{
public static $instance = null;
public $stack = array();
public function init()
{
is_null( self::$instance ) AND self::$instance = new self;
return self::$instance;
}
public function __construct()
{
\\add_action( \'the_post\', array( $this, \'toStack\' ) );
\\add_action( \'shutdown\', array( $this, \'printStack\' ) );
}
public function toStack( $post )
{
$aid = absint( $post->post_author );
! in_array( $aid, $this->stack )
$this->stack[] = $aid;
}
public function printStack()
{
printf( \'<hr />Author IDs<pre>%s</pre>\', join( "</br>", $this->stack ) );
}
}