#StackBounty: #custom-taxonomy #search WordPress Search – display taxonomy terms in results

Bounty: 50

I have a custom post type of Hotel. Hotels can be can be categorised with the taxonomy Resort.

On my search page I need to be able to list hotels and taxonomy terms in the results, as separate results. eg:

Resort Name
Hotel Name
Hotel Name
Hotel Name

Resorts should come first, followed by hotels and anything else. As far as I know taxonomy terms are not shown by default in WordPress search.

In my functions.php I’m currently limiting the search to specific post types:

function filter_search($query) {
// Don't run in admin area
if(!is_admin()) {
    // Limit search to posts
    if($query->is_main_query() && $query->is_search()) {
        $query->set('post_type', array('hotel', 'post', 'activities', 'page'));

    // Return query
    return $query;

add_filter('pre_get_posts', 'filter_search');

Then in my search.php I am grouping the results by post type:

<?php $types = array('hotel', 'post', 'activities', 'page');
foreach( $types as $type ){

echo '
'; ?>

Hotel: Activity: Blog Post: Page: Page: ">

" class="button">View Page

</div> <?php } } rewind_posts(); echo '</div> '; } ?>

What I’m struggling with is how to tell WordPress to show the taxonomy term (Resort) in the results as it’s own result. Can anybody help?

Get this bounty!!!

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.