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.

as always after struggling my mind for 3 days with a problem i decide to ask for help here.

Im trying to create an advance search page with taxonomies and keyword field. You can see what i actually got in http://alianzasuperior.com/empleo/busqueda-avanzada/ ( dont panic, its spanish but just think as taxonomies and you will be ok)

The keyword part is working fine. I can also create taxonomies pages for example taxonomy-job_type.php to handle an individual taxonomy and it works aswell.

The problem is when i try to search in multiple taxonomies , and multiple terms for those taxomies. I tried to figure it out with scribu plugin "query multiple taxonomies" but im not able.

Someone did something similiar for what im trying to do?

Any help or clue will me much appreciate

share|improve this question

1 Answer 1

up vote 3 down vote accepted

like other times, after posting here i found my own question. Maybe its not the smarter solution but its working for me.

Im using the new tax_query as commented in http://www.wpmods.com/query-multiple-taxonomies-in-wp-3-1/

Basically if i get 2 taxonomies with two terms for example

$job_type='full-time+free-lancer';
$job_cat='designer+programmer';

I do the following:

    $custom_query=false;
    $myquery['tax_query'] = array( 'relation' => 'AND');


        if ($_GET['job_type']){
            $job_type=explode('+',$_GET['job_type']);   
            foreach ($job_type as $k => $name){
                    $job_types[]=$name;                 
            }
            array_push($myquery['tax_query'],array('taxonomy' => 'job_type','terms' =>$job_types,'field' => 'slug' ,'operator' => 'IN'));
        $custom_query=true;
        }



        if ($_GET['job_cat']){
            $job_cat=explode('+',$_GET['job_cat']);
            foreach ($job_cat as $k => $name){
                $job_cats[]=$name;
            }
            array_push($myquery['tax_query'],array('taxonomy' => 'job_cat','terms' => $job_cats,'field' => 'slug','operator' => 'IN'));

        $custom_query=true;
        }

And then if i got more than one term i use the custom query:

if($custom_query) query_posts($myquery);

If you want to mix it with keyword search just do:

$myquery['s']= $yourKeywordVar;

Hope that helps, I just discovered and so far my tests are working fine

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.