The search form should be dynamic means when adding a new Taxonomy term should auto add in the search form. As well default WordPress category can also be added to the form.

Following are all Terms:

1- Default WordPress Category Terms
a- Computer IT
b- Graphic Designer

2- Custom Post Type (Taxonomy Name Location)
a- City Name 1
b- City Name 2

3- Custom Post Type (Taxonomy Name Job Type)
a- Part-Time
b- Full Time

Form fields Diagram

0- Keyword Field - 
1- Default Category (Terms in Dropdown) 
2- Location (Terms in Dropdown) 
3- Job Type (Terms in Dropdown) - 
Search Button

Auto Add New Term in Form Any Term when we create new should auto add in relevant Search Form field.

Apply Conditions: With single field use, search should be working as well with all field use search also works.

I am trying to use this code.

Search Form Field:

<form action="search" method="get">
        <input type="search" name="search_text" />
        <select name="type">
            <option>Select Type</option>
$categories = get_categories();
foreach($categories as $category) {
<option value="<?php echo $category->name; ?>"><?php echo $category->name;?></option>
        <button type="submit" name="">Submit</button>

Search Template Code:


if($_GET['search_text'] && !empty ($_GET['search_text']))
    $text = $_GET['search_text'];

if($_GET['type'] && !empty ($_GET['type']))
    $type = $_GET['type'];


            $arg = array(
                'post_type' => $type,
                'post_per_page' => -1,
                's' => $text,
                'exact' => true,
                'sentence' => true
            $query = new WP_Query($arg);
            while($query->have_posts()) : $query->the_post();
            <h5><?php echo the_title(); ?></h5>
                    if(get_post_type() == 'post'){ echo 'Post';}
                    if(get_post_type() == 'Computer'){ echo 'Computer';}
                    if(get_post_type() == 'Designer'){ echo 'Designer';}
                    if(get_post_type() == 'New Category'){ echo 'New Category';}
        <?php endwhile; wp_reset_query();?>


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.