Uncode: Create Custom Search Shortcode
1 min read

Uncode: Create Custom Search Shortcode

Uncode: Create Custom Search Shortcode
Photo by Heliberto Arias / Unsplash

Uncode has a search module that you could use, but what if you only want to search for a certain post type?

WP Search Block

Without any plugins you could create an easy search form inside a shortcode.

Here is an example:

function filter_jobs( $search ) {

    $search = '
    <form role="search" method="get" id="searchform" action="' . home_url( '/' ) . '" >
    <div class="search-container-inner">
    <label class="screen-reader-text" for="s">' . __('Search for:') . '</label>
        <input class="search-field form-fluid form-xl" type="text" value="' . get_search_query() . '" name="s" id="s" placeholder="keres├ęs" />
        <input type="hidden" name="post_type" value="career" />
        <i class="fa fa-search3"></i>
    </div>
    </form>';

    return $search;
}
add_shortcode('filter-jobs', 'filter_jobs');

Here is added the Shortcode [filter-jobs]. It also has the correct classes from Uncode, so it looks like this:

To search for a certain post type only, take a closer look to the:

 <input type="hidden" name="post_type" value="career" />

Here the value determents the post type search.