Include search tags and users in my search results system
This is my codes for search posts by ajax:
PHP:
public function search_posts(){
try {
$data = $_POST['content'];
$data = wp_parse_args( $data, array(
'post_type' = 'post',
'post_status' = 'publish',
) );
if ($data['s']){
global $theme_query;
$theme_query['s'] = explode(' ', $data['s']);
}
$query = new WP_Query($data);
$data = array();
foreach ($query-posts as $search_post) {
$search_post = get_post($search_post);
$search_post-permalink = get_permalink($search_post-ID);
$data[] = $search_post;
}
$search_term = $_POST['content']['s'];
$resp = array(
'success' = true,
'data' = array(
'posts' = $data,
'total' = $query-found_posts,
'count' = $query-post_count,
'pages' = $query-max_num_pages,
'search_term' = $search_term
)
);
} catch (Exception $e) {
$resp = array(
'success' = false
);
}
wp_send_json($resp);
}
HTML AJAX Template:
script type="text/template" id="search_preview"
# _.each(posts, function(search_post){ #
div class="item-search"
a href="{{= search_post.permalink }}"
{{= search_post.post_title.replace( search_term, 'p' + search_term + "/p" ) }}
/a
/div
# }); #
I successfully make ajax search for posts it's working fine now I need to include the search for users and tags in the search results like Facebook can search tags and users and pages at the same time.
I can search for users only or for tags only but I failed to merge all the results.
Anyone can help me on this?