Show all sub categories in filter sidebar by default

Thanks again for the pointer ihor. I didn’t manage to code it as orignally intended, but I found a way to show a pre-defined list of categories (names and IDs of categories are hardcoded in this solution), independent of the active (current) category. This way it will always be the full list of categories that is shown and not just the one that the user has clicked on.

I also added an additional css class as an attribute to be able to specifically target the category list and custom style it.

The (hardcoded) approach is not really elegant, but it might help someone else nevertheless:

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' => 'Category Label',
					'required' => 'false',
					'type' => 'radio',
					'options' => [
						'0' => 'All Categories', '22' => 'Category Name One', '30' => 'Category Name Two', '25' => 'Category Name Three', '29' => 'Category Name Four',
					],
					'attributes' => [
						'class' => [
							'filter_categories',
						]
					],
				]
			);
		}
		return $form_args;
	},
	1000,
	2
);
2 Likes