I have a site with diffrent post types. Two of them are the 'post' post type and the other one is 'charity', for both pages I have an index, the normal index.php and a diffrent page template for charity.

I used a plugin called taxonomy filters to filter the category and a custom taxonomy on 'charity'. for 'post' I created an other widget that only searches for category's.

This works amazing, the only thing is that I get redirected to the search.php template. No problem, I thought, and I made some conditional statements on search, where at diffrent post types diffrent widgets will be shows.

so in short it is something like:

<?php if ( 'charity' == get_post_type() ){ 
    //html for charity
} else ( 'post' == get_post_type() ){
    if ( 'post' == get_post_type() ){ 
//html for posts and search

Now the filtering is working amazingly good, when I'm on charity and i select a cat and a term it will direct to search, but keep the same template with te checkboxes still as they where.

BUT.. and here comes the real problem.. When I want to search something normally via the searchform, and it belongs to one of the two post types, it will (ofcourse..) take that template, including the filters of that post type.

can I prefend that?

I want the filters only to show up when redirected from that post type index.. Isn't there something as if redirected from index.php? that would be amazing !

  • I'm not sure i understand the question correctly, but you can use parameters to filter the search results: yoursite.com/?s=a&post_type=charity will only list charity posts – passatgt Jan 17 '14 at 14:12
  • Sorry for my unclear question, english is not my first language. I know that you can add parameters to filter only one post type, but my problem is that I have some if statements in my search.php that change the layout for the two post types, and the rest (else). But when I use the normal searchform (so not search with my filter checkboxes) I was to have an other template than when I search from the indexpage of the post type – Maartje Jan 17 '14 at 14:21
  • 1
    You may be able to use the somewhat (but only somewhat) reliable $_SERVER['HTTP_REFERER'] variable, but I am also not 100% sure I understand you. – s_ha_dum Jan 17 '14 at 14:42
  • @s_ha_dum Thanks, that is indeed what I am looking for I guess. atm I am trying this solution: wordpress.stackexchange.com/questions/35775/… – Maartje Jan 17 '14 at 14:44
  • Just an idea, I've came across this article wpsnipp.com/index.php/template/…, it might help you out somehow to better arrange your search templates and results. Good luck! – Adriano Monecchi Jun 17 '16 at 18:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.