".
/**
* Treat only the "final" front-end search page load, not AJAX suggestions.
* Also, only act when user didn't choose a category (no product_cat or product_cat=0).
*/
function d10_is_final_search_request( $q ){
if ( is_admin() ) return false;
if ( function_exists('wp_doing_ajax') && wp_doing_ajax() ) return false; // ignore AJAX suggestions
if ( defined('REST_REQUEST') && REST_REQUEST ) return false; // ignore REST endpoints
if ( ! ($q instanceof WP_Query) ! $q->is_main_query() ! $q->is_search() ) return false;
// Inspect raw GET to decide whether user selected a category
$pc = isset($_GET['product_cat']) ? $_GET['product_cat'] : null;
$no_selected_category = ( $pc === null $pc === '' $pc === '0' || $pc === 0 );
return $no_selected_category;
}
/**
* Normalize query (remove product_cat=0) and force products for final search page only.
*/
add_action('pre_get_posts', function( $q ){
if ( ! d10_is_final_search_request($q) ) return;
// If the form sent product_cat=0, drop it and any bogus 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);
}
}
// Keep searches on products only (so title/content search stays in products)
$q->set('post_type', array('product'));
}, 5);
/**
* Only on final search page: join tag tables so search matches product_tag name/slug.
*/
add_filter('posts_join', function( $join, $q ){
if ( ! d10_is_final_search_request($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;
}, 10, 2);
/**
* Only on final search page: extend WHERE to include product_tag name/slug LIKE 's'.
*/
add_filter('posts_where', function( $where, $q ){
if ( ! d10_is_final_search_request($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;
}, 10, 2);
/** Avoid duplicates when multiple tags match (final search page only). */
add_filter('posts_distinct', function( $distinct, $q ){
if ( ! d10_is_final_search_request($q) ) return $distinct;
return 'DISTINCT';
}, 10, 2);
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