[Support request] Custom Search Results Page for Custom Post Type

Home Forums Support [Support request] Custom Search Results Page for Custom Post Type

Home Forums Support Custom Search Results Page for Custom Post Type

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #532345
    Dev

    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.

    http://bit.ly/2GgGsBq

    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?

    GeneratePress 2.0.2
    GP Premium 1.6
    #533090
    Tom
    Lead Developer
    Lead Developer

    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.

    #533142
    Dev

    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’ );

    #533222
    Tom
    Lead Developer
    Lead Developer

    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.

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.