I am trying to use a search from
I am able to search for custom post types but unable to do so for authors.
I am using the following search form.
<form role="search" method="get" id="searchform" action="<?php echo home_url( '/' ); ?>">
<div class="input-box">
<input name="s" id="s" type="text" class="form-control" placeholder="What you are looking for...">
</div>
<div class="selection-box">
<select name="post_type" id="basic" class="selectpicker show-tick form-control">
<option value="job_listing">Listing</option>
<option value="product">Shop</option>
<option value="author">Author</option>
<option value="">All</option>
</select>
</div>
<div class="search-btn">
<input type="submit" class="form-control" value="search">
</div>
</form>
I am trying to use a search from
I am able to search for custom post types but unable to do so for authors.
I am using the following search form.
<form role="search" method="get" id="searchform" action="<?php echo home_url( '/' ); ?>">
<div class="input-box">
<input name="s" id="s" type="text" class="form-control" placeholder="What you are looking for...">
</div>
<div class="selection-box">
<select name="post_type" id="basic" class="selectpicker show-tick form-control">
<option value="job_listing">Listing</option>
<option value="product">Shop</option>
<option value="author">Author</option>
<option value="">All</option>
</select>
</div>
<div class="search-btn">
<input type="submit" class="form-control" value="search">
</div>
</form>
You should create pre_get_posts
filter and trigger in the $query->is_search()
to check if post_type
is set to author
and if it is then unset post_type
to posts or what evver you want and set author parametrs to $query
object.
related links:
https://codex.wordpress.org/Plugin_API/Action_Reference/pre_get_posts https://codex.wordpress.org/Class_Reference/WP_Query#Author_Parameters
Or you should create another select, listing all users and give it a name of Author Parametrs
found in wp_query