wxr_authors_list( int[] $post_ids = null )

In this article

Outputs list of authors with posts.

Parameters

$post_idsint[]optional
Array of post IDs to filter the query by.

Default:null

Source

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>' . (int) $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";
	}
}

Changelog

VersionDescription
3.1.0Introduced.

User Contributed Notes

You must log in before being able to contribute a note or feedback.