hello i want to hide some categories from the listing search filter how to do it ?? thanks
If you mean keeping the categories for listings but hiding them for filtering only, please try this PHP snippet. Please just change 1,2,3
on the categories id which you want to hide in the listing filter form
add_filter(
'hivepress/v1/forms/listing_filter',
function( $form ) {
$categories = [1,2,3];
foreach($categories as $category){
unset($form['fields']['_category']['options'][$category]);
}
return $form;
},
1000
);
Hello thanks for your return, yes i want to keep the categories and hide them from search filter i still having the categories in the filter i already added the snippet
Please make sure that you have changed 1,2,3
on the categories ids which you want to hide
Thanks again for your answer but the snippet isn’t working even i changed the numbers to the categorie number that i want to hide
Please make sure that the snippet was correctly added with Code Snippets or another similar plugin. Also, please check if you have correctly copied categories ids which you want to hide in the listing filter form. It was tested locally and it seems to be ok
Code snippet and listing filter form categories before changes
Code snippet and listing filter form categories after changes
Can i hide the “All Categories” option from the search box?
For example, this is my website:
yes my question was to hide some categories from" the search box" not “the filter” , the snippet for the filter is working but not the search box. example if i want to hide “all categories” and also some categories from the search box.
Thanks
If you mean listing search form then please try this PHP snippet. Please just change 1,2,3
on the categories id which you want to hide in the listing search form
add_filter(
'hivepress/v1/forms/listing_search',
function( $form ) {
if(isset($form['fields']['_category'])){
$categories = [1,2,3];
$form['fields']['_category']['option_args']['exclude'] = [];
foreach($categories as $category){
$form['fields']['_category']['option_args']['exclude'] = array_merge(
$form['fields']['_category']['option_args']['exclude'],
[$category]
);
}
}
return $form;
},
1000
);
Please try this PHP snippet
add_filter(
'hivepress/v1/forms/listing_search',
function( $form ) {
if(isset($form['fields']['_category'])){
$form['fields']['_category']['placeholder'] = null;
}
return $form;
},
1000
);
Thanks. This work only when your are in the Add Details page of the announce. Is not working in the search box in the home page for example.
Please make sure that the snippet was correctly added with Code Snippets or another similar plugin. It was tested locally and it seems to be ok
add_filter(
'hivepress/v1/forms/listing_search',
function( $form ) {
if(isset($form['fields']['_category'])){
$form['fields']['_category']['placeholder'] = null;
}
return $form;
},
1000
);
Without snippet
With snippet
Perfect Yevhen, now it works as expected. But now intetad of showing that line as defeult, can we show one of the categories as the default selected option.
I mean, instead of this:
Show this:
Please try this PHP snippet and please change the number 1
on the category id which you want to show in this field as a placeholder
add_filter(
'hivepress/v1/forms/listing_search',
function( $form ) {
if(isset($form['fields']['_category'])){
$form['fields']['_category']['placeholder'] = null;
$form['fields']['_category']['default'] = 1;
}
return $form;
},
1000
);
Thanks Yevhen, that’s what we need!
Is it possible to hide only subcategories?
If you mean hiding these in the drop-down there’s no such option at the moment (without customizations), the drop-down shows the full category hierarchy.
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.