1 2 3 4 5 6 7 8 9 10 11 12 | add_action('posts_search', function($search, $query){ global $wpdb; if ($query->is_main_query() && !empty($query->query['s'])) { $sql = " OR EXISTS (SELECT * FROM {$wpdb->postmeta} WHERE post_id={$wpdb->posts}.ID and meta_key = 'product_no' and meta_value like %s)"; $like = '%' . $wpdb->esc_like($query->query['s']) . '%'; $search .= $wpdb->prepare($sql, $like); } return $search; },2,2); |
只需要将上面的字段“product_no”替换成你所需的相关字段即可。
原文链接:https://xiaohost.com/2670.html,转载请注明出处。
评论0