Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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

1 Answer 1

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']);
else
    // 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);
        break;
    default:
        // default search stuff
}
share|improve this answer
1  
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. –  t f Apr 21 '13 at 21:10

Your Answer

 
discard

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.