antonpuz
antonpuz

Reputation: 3316

define which fields to search from admin panel in wordpress

In my wordpress site, when i use the search it searches all the fields of the post. I am looking for a way to define which fields it will look for from the default search of wordpress.

there are many manuals on creating your own custom search, but i am looking to make changes from dashboard or from search.php

any suggestions?

Upvotes: 0

Views: 212

Answers (1)

Moeed Farooqui
Moeed Farooqui

Reputation: 3622

Here is the example :

<form role="search" method="get" id="searchform" action="<?php echo home_url( '/' ); ?>">
        <input type="text" name="s" id="s" value="Enter keywords ..." onfocus="if(this.value==this.defaultValue)this.value='';" onblur="if(this.value=='')this.value=this.defaultValue;"/><br />
        <select name="post_type">
            <option value="">Choose Category:</option>
            <option value="">All Categories</option>
            <option value="post_type_a">Post Type A</option>
            <option value="post_type_b">Post Type B</option>
             <option value="post_type_c">Post Type C</option>
        </select><br />
        <input type="submit" id="searchsubmit" value="Search Help" />
    </form>

If you dont want to show the custom post types in drop down you can assign the values in hiden fields also, something like below.

<input type="hidden" name="post_type[]" value="post_type_one" />
<input type="hidden" name="post_type[]" value="post_type_two" />
<input type="hidden" name="post_type[]" value="post_type_three" />

Upvotes: 2

Related Questions