". /** * Normalize search query (remove product_cat=0) and optionally force product post type. */ add_action('pre_get_posts', 'd10_fix_search_product_cat_zero', 5); function d10_fix_search_product_cat_zero( $q ){ if ( is_admin() ! ($q instanceof WP_Query) ! $q->is_main_query() || ! $q->is_search() ) { return; } // If the form sent product_cat=0, remove it (and any matching tax_query clause) $pc = $q->get('product_cat'); if ( $pc === '0' || $pc === 0 ) { $q->set('product_cat', '' ); $tax_query = (array) $q->get('tax_query'); if ( $tax_query ) { $filtered = array(); foreach ( $tax_query as $clause ) { $is_prod_cat = is_array($clause) && isset($clause['taxonomy']) && $clause['taxonomy'] === 'product_cat'; $is_zero = is_array($clause) && isset($clause['terms']) && ( $clause['terms'] === 0 || $clause['terms'] === '0' || $clause['terms'] === array(0) || $clause['terms'] === array('0') ); if ( $is_prod_cat && $is_zero ) { continue; // drop bogus clause } $filtered[] = $clause; } $q->set('tax_query', $filtered); } } // Optional: keep searches on products only $q->set('post_type', array('product')); } /** Helper: determine if this is the main front-end product search query */ function d10_is_product_search( $q ){ return ( ! is_admin() && ($q instanceof WP_Query) && $q->is_main_query() && $q->is_search() ); } /** * Join tag tables so search can match product_tag name/slug */ add_filter('posts_join', 'd10_join_tags_for_search', 10, 2); function d10_join_tags_for_search( $join, $q ){ if ( ! d10_is_product_search($q) ) return $join; global $wpdb; if ( strpos($join, $wpdb->term_relationships) === false ) { $join .= " LEFT JOIN {$wpdb->term_relationships} tr ON (tr.object_id = {$wpdb->posts}.ID)"; } if ( strpos($join, $wpdb->term_taxonomy) === false ) { $join .= " LEFT JOIN {$wpdb->term_taxonomy} tt ON (tt.term_taxonomy_id = tr.term_taxonomy_id AND tt.taxonomy='product_tag')"; } if ( strpos($join, $wpdb->terms) === false ) { $join .= " LEFT JOIN {$wpdb->terms} t ON (t.term_id = tt.term_id)"; } return $join; } /** * Extend WHERE to include product_tag name/slug LIKE the search term */ add_filter('posts_where', 'd10_where_include_product_tags', 10, 2); function d10_where_include_product_tags( $where, $q ){ if ( ! d10_is_product_search($q) ) return $where; global $wpdb; $term = $q->get('s'); if ( ! $term ) return $where; $like = '%' . $wpdb->esc_like($term) . '%'; $where .= $wpdb->prepare( " OR (tt.taxonomy='product_tag' AND (t.name LIKE %s OR t.slug LIKE %s))", $like, $like ); return $where; } /** Avoid duplicate rows when multiple tags match */ add_filter('posts_distinct', 'd10_search_distinct', 10, 2); function d10_search_distinct( $distinct, $q ){ if ( ! d10_is_product_search($q) ) return $distinct; return 'DISTINCT'; }
Notice: Function _load_textdomain_just_in_time was called incorrectly. بارگذاری ترجمه برای دامنه woodmart زودتر از حد مجاز فراخوانی شد. این معمولاً نشان‌دهندهٔ اجرای کدی در افزونه یا پوسته است که خیلی زود اجرا شده است. ترجمه‌ها باید در عملیات init یا بعد از آن بارگذاری شوند. Please see Debugging in WordPress for more information. (این پیام در نگارش 6.7.0 افزوده شده است.) in /home/dayereco/public_html/wp-includes/functions.php on line 6121

Warning: Cannot modify header information - headers already sent by (output started at /home/dayereco/public_html/wp-content/themes/woodmart-child/functions.php:2) in /home/dayereco/public_html/wp-includes/pluggable.php on line 1450

Warning: Cannot modify header information - headers already sent by (output started at /home/dayereco/public_html/wp-content/themes/woodmart-child/functions.php:2) in /home/dayereco/public_html/wp-includes/pluggable.php on line 1453