custom post types - How do i search authors from search form using author's name

admin2025-01-08  4

I am trying to use a search from

  1. authors,
  2. listings(i.e custom post type)
  3. products(i.e custom post type)

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

  1. authors,
  2. listings(i.e custom post type)
  3. products(i.e custom post type)

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>
Share Improve this question edited Sep 10, 2015 at 0:17 terminator asked Sep 9, 2015 at 23:47 terminatorterminator 6151 gold badge6 silver badges30 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

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

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1736270175a1408.html

最新回复(0)