custom search
-
This function doesn work well
// --- RICERCA PER NOME su custom fields (front-end e admin) ---
function custom_search_query($query) {
if ($query->is_search && isset($query->query_vars['s']) && !empty($query->query_vars['s'])) {
$searchterm = $query->query_vars['s'];
$custom_fields = array('function_name'); // campi meta da cercare
$meta_query = array('relation' => 'OR');
foreach ($custom_fields as $cf) {
$meta_query[] = array(
'key' => $cf,
'value' => $searchterm,
'compare' => 'LIKE'
);
}
// Disabilita ricerca standard testo
$query->set('s', '');
$query->set('meta_query', $meta_query);
}
}
add_action('pre_get_posts', 'custom_search_query');Imagine I have an apartment (post type=post) which has for name (meta= function_name): 6805 Martina, well, if I write “martina”, or “mar” or “ma”, I get result(s), if I write 6805, I get nothing. Consider that I have another apartment “Sunbeach B5”, if I write B5 it works, I get result(s), how can I fix it?
The page I need help with: [log in to see the link]
Viewing 5 replies - 1 through 5 (of 5 total)
Viewing 5 replies - 1 through 5 (of 5 total)
You must be logged in to reply to this topic.