Select category

  • Author
  • vheo

    Hello, how can i change category select field in search form to not to display only actual tree of category with current as a root? E.g. if we have categories like
    And i selected cat2 then options in select field are only cat2, cat2.1 and cat2.2 but i’d like to have also choose with cat1 and cat3. Is it possible? I think that its sth about options array filtering in class-select but firstly i’d ask dev 😉

    $options = array_filter(
    			function( $option ) use ( $current ) {
    				$parent = hp\get_array_value( $option, 'parent' );
    				return ( is_null( $current ) && is_null( $parent ) ) || ( ! is_null( $current ) && $parent === $current );

    If i try to disable filter or delete scnd condition (! is_null( $current ) && $parent === $current) there is Fatal error: Allowed memory size of 536870912 bytes exhausted (tried to allocate 20480 bytes)


    There’s no easy way to do this unfortunately (if you mean expanding the whole category tree by default), if you’re familiar with PHP please try to use the “hivepress/v1/forms/listing_filter” hook:

    	function( $form ) {
    		$form['fields']['_category']['options'] = [
    			1 => 'custom',
    			2 => 'options',
    			3 => 'here',
    		return $form;

    Please never edit the HivePress file directly because any changes will be erased on update. Also, here’s a link to related topic that may help


    Now it’s hard to explore category, e.g. when i’m in cat 2 i can not go to cat 1 without getting back to ‘all categories’ :((
    So now the only way is to insert options by static code? I just want to disable filter which return false for categories which are not in current parent category.


    Here’s example.
    Try this:
    1. Select category e.g. “1 os. pokoje na stancji”
    2. Try to change category to another e.g. “1 os. pokoje w mieszkaniu studenckim”

    You can not do it without going to “Wszystkie categories (All categories)” between 1 and 2nd step 🙁


    This was the initial idea, because showing all categories may confuse users (if there are a lot of categories), the assumption is that users will narrow down their search by selecting categories from parent to child and they don’t need to return one level back (at least often). It works like with folders in the filesystem, you see only contents of the current folder and the folder path.

    You can try adding a separate attribute for the number of rooms, and use categories for apartment types instead, so users will be able to switch the number of rooms without changing the category.

    Also, I plan to add an option for moving the category filter to the search bar so there would be a drop-down with all categories, but there’s no ETA for this feature.


    If you’re familiar with PHP you can supply the category tree as a list of options in the code snippet suggested above, e.g. with this function

Viewing 7 posts - 1 through 7 (of 7 total)

You must be logged in to reply to this topic.


Sign In

Don't have an account? Register

Forgot password?


Already have an account? Sign In

Forgot password?

Reset Password

Please enter your username or email address, you will receive a link to create a new password via email.