Is it possible not to show a specific category in the search bar?

Hi,Team. Thank you for a great plugin.

Is it possible not to show a specific category in the search bar?
not by a user’s roll, it’s for everyone
and I still want users to be able to chose this category when they submit listings.
I want only not showing the category name on front-end search bar when users search.

I want it to work as below:

  1. If user doesn’t know which category to chose, he can chose “undefined”
  2. Admin can set it to right category manually so the listing will be searchable in right category.
  3. Problem is : users still can see “undefined” in search bar <—- I want to hide this.

I’ve been struggling with codes for hours but none of them didn’t work :cold_sweat:

add_filter(
	'hivepress/v1/forms/listing_search',
	function( $form ) {
		$disabled_categories_ids = [373];
	if(isset($form['fields']['_category'] ['options'])){
		foreach($disabled_categories_ids as $category_id){
		unset($form['fields']['_category']['options'][$category_id]);
		}
	}
	return $form;
	},
	1000,
);

Please help me!
Thank You in advance :slight_smile:

Hi,

Sorry, there’s no simple code snippet for this, it would require a custom implementation. If customizations beyond the available features are required for your site, please consider hiring someone for custom work https://fvrr.co/32e7LvY

Hi, andrii
Thank you for checking

Is it right to use ‘hivepress/v1/forms/listing_search’ hook ?
When I use this code it hides all options.

add_filter(
	'hivepress/v1/forms/listing_search',
	function( $form ) {
		unset($form['fields']['_category']['options']);
	return $form;
	},
	1000,
	2
);

I found another way to hide category.
It works for my purpose on front page, but it replaces a whole site if there have a word “undefined” in the contents.

I think this should be OK for now.
I don’t know if I can say it a solution though.
I’ll post if I found a better way.

Thank you.

add_filter('the_content', function($content) {
$content = str_replace('undefined', '', $content);
return $content;
});

Also, it is possible to remove a category from the selection in the listing search form in this way.

add_filter(
	'hivepress/v1/forms/listing_search',
	function($args){
		if(isset($args['fields']['_category'])){
			$args['fields']['_category']['option_args']['exclude'] = [put listing category IDs here];
		}
		
		return $args;
	},
	1000
);
2 Likes

yevhen
Thank you

Besides that, is it possible to change words in only in search bar?
If there is a code snippet for this.
Thank you

Could you explain more about the expected result for this issue? Which words do you want to change in the search bar? If it is possible, please provide screenshots.

Thank you for your reply.
since we used a replace function, we now use it for changing word.

$content = str_replace('undefined', 'uncategorized', $content);

it looks wired but in my language sometimes a word changes for submitting and searching purpose.
I want something like replacing word “undefined” to “uncategorized” only in search bar.
Now the code above working but it replaces a whole site if there have a word “undefined” in the contents.

Thank you in advance.

Please follow these instructions to translate any static text within HivePress, its themes, or extensions How to translate HivePress - HivePress Help Center

It is possible to translate default WordPress words in Loco Translate/WordPress

1 Like

Thank you for your instruction. But my question is not about translating.
Your code snippet for hiding a category name from search bar working fine.
Besides that I wanted to know how I can change a category name only in search bar because sometimes in my language, a word varies for submitting and searching.
Something like past tense and present tense in English.
Thank you for your help :slight_smile:

Sorry, there’s no simple code snippet for this, it would require a custom implementation. If customizations beyond the available features are required for your site, please consider hiring someone for custom work Fiverr - Freelance Services Marketplace

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.

Hi, Team.

Is it possible not to show a specific category in the search bar? I have many categories, but there are some I do not want to display in the search bar. Is there a snippet that can help me exclude certain categories?

Hi,

Please check this sample topic.