Pergunta

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

Foi útil?

Solução 2

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

Outras dicas

Like you I am also digging in depth of wordpress multiple search, check out my question in wordpress stackexchange, it might help you.

Till yet I also had no success in it.

https://wordpress.stackexchange.com/questions/27158/wordpress-multiple-category-search

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top