Extending wordpress search to include excerpts and taxonomies?

Apologies for the lack of code, but I have no idea where to start with this – is it possible to extend WordPress’s search function to include excerpts and (custom) taxonomies as well as the standard title and post content in search results? i.e. search results don’t include posts that contain keywords found in excerpts or taxonomies, is it possible to include them?

Ideally, I’d like to do this without a plugin if possible, is there a way to extend it via functions.php?

Read More

Thanks for any pointers.

Osu

Related posts

1 comment

  1. With WordPress 4.2.2 I’m using the following (admittedly fragile) method to search excerpts as well as the content and title without a plugin.

    This is the relevant snippet from functions.php.

    add_filter('posts_where', 'custom_posts_where');
    
    function custom_posts_where($where) {
        if (is_search()) {
            $where = preg_replace(
                "/(w+).post_title LIKE ('%.*?%')/",
                "$1.post_title LIKE $2) OR ($1.post_excerpt LIKE $2",
                $where);
        }
    
    return $where;
    }
    

Comments are closed.