Commit b432cb6d authored by Noemie Kerroux's avatar Noemie Kerroux

Update search.php

parent 8637334c
......@@ -21,7 +21,12 @@ class WPGlobalSearch {
],
'posts_per_page' => (!empty($args['posts_per_page'])) ? $args['posts_per_page'] : 12,
'search_if_empty' => (!empty($args['search_if_empty'])) ? $args['search_if_empty'] : true,
'taxonomies' => (!empty($args['taxonomies'])) ? $args['taxonomies'] : []
'taxonomies' => (!empty($args['taxonomies'])) ? $args['taxonomies'] : [],
'search_on' => [
'post_title' => ( (!empty($args['search_on']) && isset($args['search_on']['post_title']) ) ? $args['search_on']['post_title'] : true ),
'post_content' => ( (!empty($args['search_on']) && isset($args['search_on']['post_content'])) ? $args['search_on']['post_content'] : true ),
'post_metas' => ( (!empty($args['search_on']) && isset($args['search_on']['post_metas'])) ? $args['search_on']['post_metas'] : true ),
]
];
$articles = [];
......@@ -38,17 +43,16 @@ class WPGlobalSearch {
$post_metas_likes = "";
$array_keys = array_keys($query_array);
$last_key = end($array_keys);
foreach ($query_array as $key => $q) {
$post_title_likes .= "p.post_title LIKE '%" . $q . "%' ";
$post_content_likes .= "p.post_content LIKE '%" . $q . "%' ";
if($default_args['search_on']['post_title']){ $post_title_likes .= "p.post_title LIKE '%" . $q . "%' "; }
if($default_args['search_on']['post_content']){ $post_content_likes .= "p.post_content LIKE '%" . $q . "%' "; }
$t_name_likes .= "t.name LIKE '%" . $q . "%' ";
$post_metas_likes .= "pm.meta_value LIKE '%" . $q . "%' ";
if($default_args['search_on']['post_metas']){ $post_metas_likes .= "pm.meta_value LIKE '%" . $q . "%' "; }
if($key != $last_key){
$post_title_likes .= "OR ";
$post_content_likes .= "OR ";
if($default_args['search_on']['post_title']){ $post_title_likes .= "OR "; }
if($default_args['search_on']['post_content']){ $post_content_likes .= "OR "; }
$t_name_likes .= "OR ";
$post_metas_likes .= "OR ";
if($default_args['search_on']['post_metas']){ $post_metas_likes .= "OR "; }
}
}
......@@ -82,17 +86,18 @@ class WPGlobalSearch {
if(!empty($query)){
$db_query .= "AND (
(
(
" . ( !empty($post_title_likes) ? $post_title_likes . " OR " : "" ) . $post_content_likes . "
)
AND
(
" . ( (!empty($post_title_likes) || !empty($post_content_likes)) ? "(" : "" ) . "
" . ( !empty($post_title_likes) ? $post_title_likes . (!empty($post_content_likes) ? " OR " : "" ) : "" ) . ( !empty($post_content_likes) ? $post_content_likes : "" ) . "
" . ( (!empty($post_title_likes) || !empty($post_content_likes)) ? ") AND (" : "" ) . "
(p.post_type LIKE 'page'
AND pm.meta_key LIKE '_wp_page_template'
AND pm.meta_value NOT IN " . self::get_formatted_sql_element($default_args['forbidden_templates']) . ")
OR
(p.post_type NOT LIKE 'page')
)
" . ( (!empty($post_title_likes) || !empty($post_content_likes)) ? ")" : "" ) . "
)
OR
(
......@@ -116,7 +121,6 @@ class WPGlobalSearch {
$last_page = ($count_pages == $page);
}
return array(
'errors' => $errors,
'results' => $articles,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment