Yoast\WP\SEO\Helpers

Author_Archive_Helper::author_has_public_posts_wp()publicYoast 1.0

Returns whether the author has at least one public post.

Note: It uses WP_Query to determine the number of posts, not the indexables table.

Метод класса: Author_Archive_Helper{}

Хуков нет.

Возвращает

true|false. Whether the author has at least one public post.

Использование

$Author_Archive_Helper = new Author_Archive_Helper();
$Author_Archive_Helper->author_has_public_posts_wp( $user_id );
$user_id(строка) (обязательный)
The user ID.

Код Author_Archive_Helper::author_has_public_posts_wp() Yoast 20.0

public function author_has_public_posts_wp( $user_id ) {
	$post_types        = \array_intersect( $this->get_author_archive_post_types(), $this->post_type_helper->get_indexable_post_types() );
	$public_post_stati = \array_values( \array_filter( \get_post_stati(), 'is_post_status_viewable' ) );

	$args  = [
		'post_type'   => $post_types,
		'post_status' => $public_post_stati,
		'author'      => $user_id,
	];
	$query = new WP_Query( $args );

	if ( ! empty( $query->posts ) ) {
		return true;
	}

	return false;
}