Yoast\WP\SEO\Helpers
Post_Helper::update_has_public_posts_on_attachments()
Updates the has_public_posts field on attachments for a post_parent.
An attachment is represented by their post parent when:
- The attachment has a post parent.
- The attachment inherits the post status.
Метод класса: Post_Helper{}
Хуков нет.
Возвращает
true|false
. Whether the update was successful.
Использование
$Post_Helper = new Post_Helper(); $Post_Helper->update_has_public_posts_on_attachments( $post_parent, $has_public_posts );
- $post_parent(int) (обязательный)
- Post ID.
- $has_public_posts(int) (обязательный)
- Whether the parent is public.
Код Post_Helper::update_has_public_posts_on_attachments() Post Helper::update has public posts on attachments Yoast 24.9
public function update_has_public_posts_on_attachments( $post_parent, $has_public_posts ) { $query = $this->repository->query() ->select( 'id' ) ->where( 'object_type', 'post' ) ->where( 'object_sub_type', 'attachment' ) ->where( 'post_status', 'inherit' ) ->where( 'post_parent', $post_parent ); if ( $has_public_posts !== null ) { $query->where_raw( '( has_public_posts IS NULL OR has_public_posts <> %s )', [ $has_public_posts ] ); } else { $query->where_not_null( 'has_public_posts' ); } $results = $query->find_array(); if ( empty( $results ) ) { return true; } $updated = $this->repository->query() ->set( 'has_public_posts', $has_public_posts ) ->where_id_in( \wp_list_pluck( $results, 'id' ) ) ->update_many(); return $updated !== false; }