WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] search multiple taxonomies (witch checkboxes) (3 posts)

  1. grosbouff
    Member
    Posted 3 years ago #

    Hi, I would like to have a search form where the user is able to check several taxonomies to search in (using the OR operator).
    so my checkboxes elements have
    name="yclad_category[]"
    for example, which is an array.

    So I guess I have to implode this array before the query args are parsed.

    I made this :

    //explode checkboxes array when doing a search
    	$_POST = yclads_implode_checkboxes_taxonomies($_POST);
    
    function yclads_implode_checkboxes_taxonomies($request_var) {
    
    	$args = array('yclad_action','yclad_category');
    
    	foreach($request_var as $arg_key=>$arg_value) {
    		unset($value);
    		if (!in_array($arg_key,$args)) continue;
    		$value= $request_var[$arg_key];
    		if (!$value) continue;
    		if (!is_array($value)) continue;
    		$new_args[$arg_key]=implode(',',$value); //'OR' operator
    	}
    
    	$new_args = array_filter((array)$new_args);
    	$output = wp_parse_args( $new_args, $request_var );
    
    	//DEBUG
    	$yclads_debug['checkboxes_args_before']=$request_var;
    	$yclads_debug['checkboxes_args_after']=$output;
    
    	return $output;
    }

    when I print my $request->query_vars (using the hook parse_request), I got this

    Array ( [post_type] => yclad [yclad_category] => cars,casting [taxonomy] => yclad_category [term] => cars,casting )

    So by there it seems to be OK.
    But then the query do not work. No posts are returned...

    Any idea of why ?

    THanks !

  2. grosbouff
    Member
    Posted 3 years ago #

    PS : I retrograded to WP3.1 RC4 and this same script is working with it.

  3. grosbouff
    Member
    Posted 3 years ago #

    mmhh...I had not well setup the beta tester plugin. Was running under WP 3.0.5... this is fixed now, the code works fine.

Topic Closed

This topic has been closed to new replies.

About this Topic