WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is there a way to use a custom PHP template for search results of a custom post type. I know that you can have specific archive and category templates for custom post types. For example, archive-custom.php. But, the same doesn't work for search.php. Any suggestions?

share|improve this question
up vote 2 down vote accepted

According to this answer of yours, you can do the following inside your search.php:

if (isset($_GET['post_type']))
    get_template_part('search', $_GET['post_type']);
    // no post_type given

Then you have to set up the search-{post_type}.php files.

If you want to handle only some of the existing post types differently, do this by means of a switch:

$type = (isset($_GET['post_type'])) ? $_GET['post_type'] : '';
switch ($type) {
    case 'attorney':
    case 'criminal':
    case 'musician':
        get_template_part('search', $type);
        // default search stuff
share|improve this answer
Thank you!!! This is great! Really appreciate the help. – Shawn Apr 21 '13 at 20:52
Oh, glad I could help. Would you mind accepting this answer? Just click the check mark (upper left corner, below the vote counter)? This way other users can see this question has been solved and it won't get picked up by the Community bot. – tfrommen Apr 21 '13 at 21:10

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.