jeudi 5 mars 2015

Search by post, tag and category - how?


I successfully removed the page from search result. The search result is now displaying only post. Now, i want to ask that, how to make the search result include category as well as tag? Because, I have some different keywords which not in the content of post. Any code do i need to add to functions.php in order to make this work? Any solution, please? Appreciate it!


Example: I have this code to remove pages from search result.



function remove_pages_from_search() {
global $wp_post_types;
$wp_post_types['page']->exclude_from_search = true;
}
add_action('init', 'remove_pages_from_search');


And this code to highlight the title for the searched words:



function search_title_highlight() {
$title = get_the_title();
$keys = implode('|', explode(' ', get_search_query()));
$title = preg_replace('/(' . $keys .')/iu', '<u class="search-highlight"><b>\0</b></u>', $title);

echo $title;
}


If tags and categories are able to include in search result, is it possible to highlight the categories and tags as well?


Additional: I created a few websites which is under handle with wordpress multisite, is it possible to make search result displaying all the post from all the sites? Thanks!





Aucun commentaire:

Enregistrer un commentaire