Automattic\WooCommerce\Internal\ProductDownloads
DownloadableFileAttachments::handle_posts_results
Drop a downloadable product file from the main query when it is requested as a single post.
With nothing found, WordPress shows a 404 instead of the attachment page or its redirect to the file, and feeds, embeds, and theme templates have no attachment to render.
Метод класса: DownloadableFileAttachments{}
Хуков нет.
Возвращает
WP_Post[]|mixed.
Использование
$DownloadableFileAttachments = new DownloadableFileAttachments(); $DownloadableFileAttachments->handle_posts_results( $posts, $query );
- $posts(WP_Post[]|разное) (обязательный)
- Posts found by the query.
- $query(WP_Query|разное) (обязательный)
- The query.
Код DownloadableFileAttachments::handle_posts_results() DownloadableFileAttachments::handle posts results WC 11.3.0
public function handle_posts_results( $posts, $query ) {
if ( ! is_array( $posts ) || 1 !== count( $posts ) || ! $query instanceof WP_Query || ! $query->is_main_query() || ! $query->is_singular() ) {
return $posts;
}
$post = reset( $posts );
if ( ! $post instanceof WP_Post || 'attachment' !== $post->post_type || ! $this->is_hidden_attachment( $post->ID ) ) {
return $posts;
}
// Pretty permalinks set the queried object before posts are fetched, and feed titles print its title.
unset( $query->queried_object, $query->queried_object_id );
return array();
}