Title: Display author posts using search parameter (not author template/query_posts)
Last modified: August 20, 2016

---

# Display author posts using search parameter (not author template/query_posts)

 *  [multiformeingegno](https://wordpress.org/support/users/lorenzone92/)
 * (@lorenzone92)
 * [13 years, 4 months ago](https://wordpress.org/support/topic/display-all-user-posts-using-search-parameter-not-author-templatequery_posts/)
 * Is there a way to retrieve a list of all the posts by an author using search (
   example: ?s&author=xxx)? I can’t use query_posts or author template (don’t ask
   why, take it as a condition).
    And it should be a public query (the filter in
   admin panel isn’t good).
 * Thanks in advance.

Viewing 11 replies - 1 through 11 (of 11 total)

 *  Moderator [keesiemeijer](https://wordpress.org/support/users/keesiemeijer/)
 * (@keesiemeijer)
 * [13 years, 4 months ago](https://wordpress.org/support/topic/display-all-user-posts-using-search-parameter-not-author-templatequery_posts/#post-3449371)
 * So you want to use a form where users can choose from a list of authors and after
   submitting show only posts from the chosen author on the search results page?
 *  Thread Starter [multiformeingegno](https://wordpress.org/support/users/lorenzone92/)
 * (@lorenzone92)
 * [13 years, 4 months ago](https://wordpress.org/support/topic/display-all-user-posts-using-search-parameter-not-author-templatequery_posts/#post-3449374)
 * No, I’d like to be able to use authors as a search parameters. No firms needed(
   just the ability to use ?s&author=username or something like that
 *  Thread Starter [multiformeingegno](https://wordpress.org/support/users/lorenzone92/)
 * (@lorenzone92)
 * [13 years, 4 months ago](https://wordpress.org/support/topic/display-all-user-posts-using-search-parameter-not-author-templatequery_posts/#post-3449376)
 * forms needed*
    Sorry, autocorrect made some mistakes.
 *  Moderator [keesiemeijer](https://wordpress.org/support/users/keesiemeijer/)
 * (@keesiemeijer)
 * [13 years, 4 months ago](https://wordpress.org/support/topic/display-all-user-posts-using-search-parameter-not-author-templatequery_posts/#post-3449381)
 * > No forms needed
 * How would users choose the author?
 * I think this in the url works as you want it to:
    /?s=hello+world&author_name
   =admin
 *  Thread Starter [multiformeingegno](https://wordpress.org/support/users/lorenzone92/)
 * (@lorenzone92)
 * [13 years, 4 months ago](https://wordpress.org/support/topic/display-all-user-posts-using-search-parameter-not-author-templatequery_posts/#post-3449418)
 * I don’t need users to choose the author. *I* need the filter, don’t worry about
   practical use 🙂
    Anyway, the URL structure works fine, the only thing left is
   to have no search terms, I want all posts from an author to be displayed (search
   term should be blank, how can I set it to “none”?).
 *  Thread Starter [multiformeingegno](https://wordpress.org/support/users/lorenzone92/)
 * (@lorenzone92)
 * [13 years, 4 months ago](https://wordpress.org/support/topic/display-all-user-posts-using-search-parameter-not-author-templatequery_posts/#post-3449419)
 * Something like /?s=%20&author_name=username works, but if there’s something that
   sets search term to none would be better (to not display “search results for ”).
   🙂
 *  Thread Starter [multiformeingegno](https://wordpress.org/support/users/lorenzone92/)
 * (@lorenzone92)
 * [13 years, 4 months ago](https://wordpress.org/support/topic/display-all-user-posts-using-search-parameter-not-author-templatequery_posts/#post-3449427)
 * For this to be perfect I’m looking also for a way to set the search results to
   start from Xth entry, for example startfrom=6 …
 *  Moderator [keesiemeijer](https://wordpress.org/support/users/keesiemeijer/)
 * (@keesiemeijer)
 * [13 years, 4 months ago](https://wordpress.org/support/topic/display-all-user-posts-using-search-parameter-not-author-templatequery_posts/#post-3449456)
 * Is there any reason you want to use the search template?
 * with this in your theme’s functions.php you can show the author posts on a search
   template file:
 *     ```
       add_action( 'pre_get_posts', 'alter_search_query' );
       function alter_search_query( $query ) {
         // not an admin page and is the main query
         if (!is_admin() && $query->is_main_query()){
           if(is_search() && ($query->query_vars['s'] == 'none')){
   
           	$author = get_query_var('author_name');
           	if($author != '') {
             	$query->set('author_name', $author);
             	// set search query 'none' to empty string ''
             	$query->set('s', '');
             	$query->set('post_type', 'post');
             }
           }
         }
       }
       ```
   
 * the url has to be like this: /?s=none&author_name=admin
 * On the search template you can use a conditional to check if the search query
   is empty:
 *     ```
       <?php if(get_search_query() ==  '') : ?>
       <!-- do stuff for empty search query -->
       <?php else : ?>
       <!-- do stuff for not empty search query -->
       <?php endif; ?>
       ```
   
 *  Thread Starter [multiformeingegno](https://wordpress.org/support/users/lorenzone92/)
 * (@lorenzone92)
 * [13 years, 4 months ago](https://wordpress.org/support/topic/display-all-user-posts-using-search-parameter-not-author-templatequery_posts/#post-3449457)
 * Thanks for the example. Anyway I have troubles understanding what your code does
   exactly. What are the differences between that and the method with parameters
   in URL without code in functions.php?
 * Thanks again 🙂
 *  Moderator [keesiemeijer](https://wordpress.org/support/users/keesiemeijer/)
 * (@keesiemeijer)
 * [13 years, 4 months ago](https://wordpress.org/support/topic/display-all-user-posts-using-search-parameter-not-author-templatequery_posts/#post-3449459)
 * Ah yes, not really needed now, but if you want to use a offset later you can 
   use it to alter the query. Why the need to use a search template file? Is it’s
   for the layout on that page?
 *  Thread Starter [multiformeingegno](https://wordpress.org/support/users/lorenzone92/)
 * (@lorenzone92)
 * [13 years, 4 months ago](https://wordpress.org/support/topic/display-all-user-posts-using-search-parameter-not-author-templatequery_posts/#post-3449485)
 * Here’s the page [http://goo.gl/QC0P5](http://goo.gl/QC0P5).
    As you can see the
   latest 9 articles from an author. At the end a link to ALL his articles. 🙂

Viewing 11 replies - 1 through 11 (of 11 total)

The topic ‘Display author posts using search parameter (not author template/query_posts)’
is closed to new replies.

## Tags

 * [author](https://wordpress.org/support/topic-tag/author/)
 * [filter](https://wordpress.org/support/topic-tag/filter/)
 * [parameter](https://wordpress.org/support/topic-tag/parameter/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 11 replies
 * 2 participants
 * Last reply from: [multiformeingegno](https://wordpress.org/support/users/lorenzone92/)
 * Last activity: [13 years, 4 months ago](https://wordpress.org/support/topic/display-all-user-posts-using-search-parameter-not-author-templatequery_posts/#post-3449485)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
