Archived topic
Custom Search Results Page for Custom Post Type
3 replies · Started by Dev on March 27, 2018
Tom,
I am using "WeDocs" documentation and FAQ plugin which registers custom post type of "docs".
I wish to create a custom search results page similar to this URL here.
Which theme files do I need to copy in my child theme so that this particular customization is only limited to "doc" post type and does not affect the rest of the functionality?
Hi there,
I believe you would need to do something like this: https://galengidman.com/2014/06/09/custom-post-type-search-results-templates-in-wordpress/
More specifically, the search-your-cpt.php file.
Thanks Tom, Actually, that's exactly what I tried but wasn't sure what would be a good flow to keep it in the spirit of GP (upgrade proof, good quality code :-)
So, will this be a good approach?
1. copy search.php to my child theme.
2. In this file look at $post_type = $_GET['post_type'];
3. if it is My Custom Post Type ( docs, in this case), call a different template say search-docs.php with the following code?
get_template_part( 'content', 'search-docs' );
btw, I noticed that in GP's search.php you currently have following line. I thought that looked like a recursive call to the same file. That confused me a bit.
get_template_part( 'content', 'search' );
You should just be able to:
1. Copy search.php into your child theme.
2. Rename it to search-docs.php
3. Make any adjustments.