Automattic\WooCommerce\Internal\ProductDownloads
DownloadableFileAttachments::handle_posts_where
Exclude attachments stored in the woocommerce_uploads directory from marked queries.
Метод класса: DownloadableFileAttachments{}
Хуков нет.
Возвращает
string|mixed.
Использование
$DownloadableFileAttachments = new DownloadableFileAttachments(); $DownloadableFileAttachments->handle_posts_where( $where, $query );
- $where(строка|разное) (обязательный)
- WHERE clause of the query.
- $query(WP_Query|разное) (обязательный)
- The query.
Код DownloadableFileAttachments::handle_posts_where() DownloadableFileAttachments::handle posts where WC 11.3.0
public function handle_posts_where( $where, $query ) {
if ( ! is_string( $where ) || ! $query instanceof WP_Query || ! $query->get( self::EXCLUDE_QUERY_VAR ) ) {
return $where;
}
global $wpdb;
// Grouping the existing conditions keeps an OR added by another posts_where filter from escaping the exclusion.
return " AND ( 1=1 {$where} )" . $wpdb->prepare(
" AND NOT EXISTS ( SELECT 1 FROM {$wpdb->postmeta} AS wc_attached_file WHERE wc_attached_file.post_id = {$wpdb->posts}.ID AND wc_attached_file.meta_key = '_wp_attached_file' AND wc_attached_file.meta_value LIKE %s )",
$wpdb->esc_like( self::DIRECTORY ) . '%'
);
}