Remove Category Selection on the add listing page and search filter

Hello,

Hope you are doing well.

I would like to remove the Category Selection option from the add listing page from the front-end but I will do it manually on behalf of the user from the back-end.
I also don’t want to display the Category radio button on the search filter area but if that is not possible, then I want to change it to select drop down with multi select option instead of radio button.

In conclusion, I want to keep the functionality of the categories on the site but I don’t want to display them on the said locations.
Could you please share with me the codes to do that.

Thank you in advance.

Please try this PHP snippet

// Remove Category field from listing submit form
add_filter(
	'hivepress/v1/forms/listing_submit',
	function( $form ) {
		unset($form['fields']['categories']);	

		return $form;
	},
	1000
);

// Remove Category field from listing filter form
add_filter(
	'hivepress/v1/forms/listing_filter',
	function( $form ) {
		unset($form['fields']['_category']);	

		return $form;
	},
	1000
);
2 Likes

Thank you so much! it worked.

Just in case if I want to display the categories on the search page filters in the future.
Could you please provide the code to change the field of the category selection from radio button to drop down with multi select.
Thanks again :slight_smile:

Please try this PHP snippet

add_filter(
	'hivepress/v1/forms/listing_filter',
	function( $form_args, $form ) {
		
		if(isset($form_args['fields']['_category'])){
			$form_args['fields']['_category'] = array_merge(
				$form_args['fields']['_category'],
				[
					'type' => 'select',
					'multiple' => true,
				]
			);
		}

		return $form_args;
	},
	1000,
	2
);
1 Like

Thank you so much, it worked!

One thing about this code, the field label is missing. Could you please share the code with the field label.

I’m really sorry for bothering you guys.

Thanks in advance.

I believe there is a bug caused by removing the categories from the search page.

steps to reproduce:

  1. Display categories instead of listings on the listings page
  2. Remove the categories using the code from the filters
  3. try to set some filters then click filter so search for listings but doing that it takes you back to selecting the category page then you have to select the category then it takes you back to the listings page.
    When it first happened, I let it for some time but after that it went away by it self and the search page worked fine, I mean I set some filters and search and the search results returns without selecting category again.

(It might be a permalinks issue)

Hope I was able to explain well.

Regards,

  1. Please try this snippet instead. It will add label “Categories” for this field
add_filter(
	'hivepress/v1/forms/listing_filter',
	function( $form_args, $form ) {
		
		if(isset($form_args['fields']['_category'])){
			$form_args['fields']['_category'] = array_merge(
				$form_args['fields']['_category'],
				[
					'label' => 'Categories',
					'type' => 'select',
					'multiple' => true,
				]
			);
		}

		return $form_args;
	},
	1000,
	2
);
  1. Yes, this is expected behavior - if the “Display categories instead of listings” option is checked for the default Listings page or some category, then it’s not possible to search listings until the category is selected. If you already searched some listings and selected All Categories again then the layout will be switched back to the category selection page.
1 Like

In regards to the snippet, it causes a fatal Wordpress error after hitting the “Filter” button. Do you have an updated version that works when clicking the filter button, or is it always going to do this due to how the filter function works?

Sorry for the inconvenience but unfortunately there is no possibility to make categories as multiple selections. It would require advanced customization since many features rely on a single category selection.

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