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.

I have a site with different custom post types, I have two "index pages" for each one of these (where I query the posts and show) and also I include a search form on both of them. So the thing is that search forms goes by default to the search.php template, to filter search and show results only for that custom post type I'm using a hidden field on form:

<input type="hidden" name="post_type" value="staff" />

but then on the search I'd like to provide a "back" link to allow the user to go back to the index page, the thing is that I can't find an if statement that works to show different "back to" links depending of the custom post type searched.

Example: If I search for News then I'd like to have a back to News index button If the search is on Staff the button shown has to be back to Staff index.

I appreciate any help guys!
Thanks!
Juan.

share|improve this question
    
Yes, Jaypee's answer is right. Check here for some sample code to play with search results and custom post types. kvcodes.com/2014/07/… –  Varadharaj V Jul 10 at 5:17
    
It's not an answer, rather better suited as a comment. –  Mayeenul Islam Jul 10 at 6:09
    
This does not provide an answer to the question. To critique or request clarification from an author, leave a comment below their post - you can always comment on your own posts, and once you have sufficient reputation you will be able to comment on any post. –  G. M. Jul 10 at 7:22

1 Answer 1

up vote 2 down vote accepted

So I have found the solution, I leave it here if anyone needs something like this in the future.

On your search form add a hidden field:

<input type="hidden" name="post_type" value="post_type_name" />

Then on your search.php file add the following WITHIN the loop:

    <?php
    if(isset($_GET['post_type'])) {
        $type = $_GET['post_type'];
        if($type == 'post_type_name_1') {?>
        <!--Your Code for this post_type-->         
        <?php    
        } elseif($type == 'post_type_name_2') {?>
             <!--Your Code for this post_type-->
        <?php }
    }
    ?>

Best!

share|improve this answer

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.