有帖子的作者输出列表

原型

wxr_authors_list( array $post_ids = null )

参数

$post_ids (array) (Optional) 用于过滤查询的帖子ID数组。可选的。

源文件

路径:wp-admin/includes/export.php

<?php
...
	function wxr_authors_list( array $post_ids = null ) {
		global $wpdb;
		if ( !empty( $post_ids ) ) {
			$post_ids = array_map( 'absint', $post_ids );
			$and = 'AND ID IN ( ' . implode( ', ', $post_ids ) . ')';
		} else {
			$and = '';
		}
		$authors = array();
		$results = $wpdb->get_results( "SELECT DISTINCT post_author FROM $wpdb->posts WHERE post_status != 'auto-draft' $and" );
		foreach ( (array) $results as $result )
			$authors[] = get_userdata( $result->post_author );
		$authors = array_filter( $authors );
		foreach ( $authors as $author ) {
			echo "t<wp:author>";
			echo '<wp:author_id>' . intval( $author->ID ) . '</wp:author_id>';
			echo '<wp:author_login>' . wxr_cdata( $author->user_login ) . '</wp:author_login>';
			echo '<wp:author_email>' . wxr_cdata( $author->user_email ) . '</wp:author_email>';
			echo '<wp:author_display_name>' . wxr_cdata( $author->display_name ) . '</wp:author_display_name>';
			echo '<wp:author_first_name>' . wxr_cdata( $author->first_name ) . '</wp:author_first_name>';
			echo '<wp:author_last_name>' . wxr_cdata( $author->last_name ) . '</wp:author_last_name>';
			echo "</wp:author>n";
		}
	}
...
?>

其他

英文文档:https://developer.wordpress.org/reference/functions/wxr_authors_list/