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?

1 Answer 1


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
  • 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, 2013 at 21:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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