Yoast\WP\SEO\Helpers
Author_Archive_Helper::author_has_public_posts_wp
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() Author Archive Helper::author has public posts wp Yoast 26.5
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,
'update_post_term_cache' => false,
'update_post_meta_cache' => false,
'no_found_rows' => true,
'fields' => 'ids',
'posts_per_page' => 1,
];
$query = new WP_Query( $args );
if ( $query->have_posts() ) {
return true;
}
return false;
}