checkbox search (and)
-
Is it possible to change the checkbox area so that it exactly looks for the selected checkboxes?
currently, with all the tests I have done, even if I select 3 checkboxes, the search result is also just 1 checkbox, instead I wish it must have all of them is 3
-
Hi,
it is possible, i am not sure how you are adding the search fields but if you are using the WordPress API then it is just a matter to set the'operator' => 'AND'in the WP_Query https://developer.ww.wp.xz.cn/reference/classes/wp_query/#taxonomy-parametersThe custom fields extension does not have this option yet, so you would need to leave the “Search By” field empty in the form editor and in your theme functions.php file add the code below
add_filter( "adverts_list_query", function( $args ) { if( adverts_request( "search_category" ) ) { $args["meta_query"][] = array( "taxonomy" => "advert_category", "field" => "term_id", "terms" => adverts_request( "search_category" ), "include_children" => true, "operator" => "AND" ); } return $args; }In the code above i am assuming your category search field in [adverts_list] is named “search_category” and the field options are using terms_ids in the
<option>tags.this code does not work, it has an error
this is my research field
-
This reply was modified 5 years, 11 months ago by
virtualars.
-
This reply was modified 5 years, 11 months ago by
virtualars.
-
This reply was modified 5 years, 11 months ago by
virtualars.
You are correct there are two characters missing at the end of the code it should be
add_filter( "adverts_list_query", function( $args ) { if( adverts_request( "search_category" ) ) { $args["meta_query"][] = array( "taxonomy" => "advert_category", "field" => "term_id", "terms" => adverts_request( "search_category" ), "include_children" => true, "operator" => "AND" ); } return $args; } );If you would like the Varie field to search inside categories then you would need to:
– check the “use values” checkbox and next to each option enter a “value” equal to a category ID
– unset the “Search By” dropdown value
– in the above code replace"search_category"with"varie"no, I need that in the search, and you select 3 checkboxes in “varie” you must show me the ads that have exactly those 3 checkboxes, not just one
my setting: https://ibb.co/L8p9zF7
my search: https://ibb.co/2W6JV48your code:
add_filter( "adverts_list_query", function( $args ) { if( adverts_request( "varie" ) ) { $args["meta_query"][] = array( "taxonomy" => "varie", "field" => "term_id", "terms" => adverts_request( "varie" ), "include_children" => true, "operator" => "AND" ); } return $args; } );Hi,
out of office and cannot check the code on my dev machine, but it seems i made a typo on line 3 it should be$args["tax_query"][] = array(not
$args["meta_query"][] = array(Also, in the code you have line
"taxonomy" => "varie", which implicates you have a “varie” custom taxonomy registered, is that the case? WPAdverts does not do it by default so if you did not register this taxonomy manually the code will not work.Finally the search results link should be something like http://www.mysite.com/adverts/reveal_hidden=1&_form_scheme_id=5108&varie%5B%5D=Termosifoni&varie%5B%5D=Caldaia&varie%5B%5D=1000 (where 1000 is taxonomy id) because the code snippet is configured to search by term ids.
All in all it looks like searching by metas and taxonomies is mixed here, can you share a screenshot from the [adverts_add] configuration so i can see how you are confguriing the “varie” field for [adverts_add]? This will clear things up :).
-
This reply was modified 5 years, 11 months ago by
The topic ‘checkbox search (and)’ is closed to new replies.