Title: Conditional or Step Filter
Last modified: April 14, 2023

---

# Conditional or Step Filter

 *  Resolved [den1sa](https://wordpress.org/support/users/den1sa/)
 * (@den1sa)
 * [3 years ago](https://wordpress.org/support/topic/conditional-or-step-filter/)
 * Hi,
 * In Ultimate Member i have the ability to filter the contents of the memberships.
   However, what i need to do is create a conditional filter. For example…
 * If I have a list of vehicle types in one dropdown filter, e.g.
 * **VEHICLE TYPES FIELD**
   CarsVansLorrysAeroplanesHelicopters
 * When the user selects one of the items, lets say ‘Cars’, a new dropdown box appears
   with a list of cars, e.g.
 * **CAR TYPES FIELD**
   HatchbackSUVSaloon
 * I already have separate fields for each vehicle type, all i need Ultimate Member
   filter to do is show the Car Types field when Cars is selected from the Vehicle
   Type dropdown field. Or to show the Helicopter Types dropdown field when Helicopters
   is selected from the Vehicle Types dropdown field, and so on.
 * So it like having the ability to show/hide fields in the filter based on a previous
   selection in this case from the Vehicle Types Field. So if Cars is selected, 
   only the Car Types field is shown and the Helicopter Types, Van Types, etc, are
   hidden.
 * **Vehicle Types Field**—-**Sub-Type Field**
   Car———————-(Car Types) Hatchback,
   SUV, Saloon…Helicopter—————(Helicopter Types) Compound, Tandem Rotor…Vans——————–(
   Van Types) Box Van, City Van, Crew Van,…
 * Any help will be greatly appreciated.
 * Denis
    -  This topic was modified 3 years ago by [den1sa](https://wordpress.org/support/users/den1sa/).

Viewing 8 replies - 1 through 8 (of 8 total)

 *  [missveronica](https://wordpress.org/support/users/missveronicatv/)
 * (@missveronicatv)
 * [3 years ago](https://wordpress.org/support/topic/conditional-or-step-filter/#post-16655229)
 * [@den1sa](https://wordpress.org/support/users/den1sa/)
 * You can start and try this code snippet built according this guide:
 * [https://docs.ultimatemember.com/article/1539-choices-callback-feature-in-um-2-1](https://docs.ultimatemember.com/article/1539-choices-callback-feature-in-um-2-1)
 * The callbacks to use are:
    `custom_vehicles_list_dropdown` `get_vehicle_types_dropdown`
 * Parent is your Label for the Vehicles List field
 * My Members Directory page [https://imgur.com/a/7bQ4XhJ](https://imgur.com/a/7bQ4XhJ)
 *     ```
       function custom_vehicles_list_dropdown() {
   
           $vehicles = array( 
                           "Cars"        => "Cars", 
                           "Vans"        => "Vans",
                           "Lorrys"      => "Lorrys",
                           "Aeroplanes"  => "Aeroplanes",
                           "Helicopters" => "Helicopters",
                       ); 		
   
           return $vehicles;         
       }
   
       function get_vehicle_types_dropdown( $has_parent = false ) { //get the value from the 'parent' field, sent via the AJAX post. 
   
           //get the value from the 'parent' field, sent via the AJAX post.
           $parent_options = isset( $_POST['parent_option'] ) ? $_POST['parent_option'] : false;
   
           $vehicle_options = array(
                           "Cars" => array
                                   (
                                       "Hatchback" => "Hatchback",
                                       "SUV"       => "SUV",
                                       "Saloon"    => "Saloon",
                                   ),
                           "Vans" => array
                                   (
                                       "Box Van"   => "Box Van",
                                       "City Van"  => "City Van",
                                       "Crew Van"  => "Crew Van",
                                   ),
                           "Lorrys" => array
                                   (
                                       "Lorry 1"   => "Lorry 1",
                                       "Lorry 2"   => "Lorry 2",
                                   ),
                           "Aeroplanes" => array
                                   (
                                       "Aeroplane 1" => "Aeroplane 1",
                                       "Aeroplane 2" => "Aeroplane 2",
                                   ),
                           "Helicopters" => array
                                   ( 
                                       "Compound"     => "Compound",
                                       "Tandem Rotor" => "Tandem Rotor",
                                   ),
                           );
   
           $arr_options = array();
   
           if ( ! is_array( $parent_options ) ) {
               $parent_options = array( $parent_options );
           }
   
           foreach ( $parent_options as $parent_option ) {
               if ( isset( $vehicle_options[ $parent_option ] ) ) {
                   $arr_options = array_merge( $arr_options, $vehicle_options[ $parent_option ] );
               } elseif ( ! isset( $_POST['parent_option'] ) ) {
                   foreach ( $vehicle_options as $k => $opts ) {
                       $arr_options = array_merge( $opts, $arr_options );
                   }
               }
           }
   
           //code to do something if other options are not selected or empty match
           if ( empty( $arr_options ) ) {
               $arr_options[ ] = "no vehicles";
           } else {
               $arr_options = array_unique( $arr_options );
           }
   
           return $arr_options;
       }
       ```
   
 * Add the code snippet to your active theme’s/child-theme’s `functions.php` file
   
   or use the “Code Snippets” plugin.
 * [https://wordpress.org/plugins/code-snippets/](https://wordpress.org/plugins/code-snippets/)
    -  This reply was modified 3 years ago by [missveronica](https://wordpress.org/support/users/missveronicatv/).
 *  [maximoguerrero](https://wordpress.org/support/users/maximoguerrero/)
 * (@maximoguerrero)
 * [3 years ago](https://wordpress.org/support/topic/conditional-or-step-filter/#post-16655398)
 * so must the parent drodown also be populated by call back. In my case i have 
   a static dropdown with the list filled out in the UI and the child dropdown with
   the callback.
 *  Thread Starter [den1sa](https://wordpress.org/support/users/den1sa/)
 * (@den1sa)
 * [3 years ago](https://wordpress.org/support/topic/conditional-or-step-filter/#post-16655511)
 * Thank you both for your quick responses.
 * Now that i have added the code to the Code Snippets plugin, how do i relate this
   to the Member Directory page called ‘All Services’ that corresponds to this shortcode[
   ultimatemember form_id=”6149″] ?
 *  [missveronica](https://wordpress.org/support/users/missveronicatv/)
 * (@missveronicatv)
 * [3 years ago](https://wordpress.org/support/topic/conditional-or-step-filter/#post-16655536)
 * [@den1sa](https://wordpress.org/support/users/den1sa/)
 * In your Members Directory settings at “Search Options” and “Choose filter(s) 
   meta to enable” click the button “Add New Custom Field” where you look for the
   Labels and select both Vehicle fields.
 * Enable these settings:
 *     ```
       Enable Search feature
       Enable Filters feature
       ```
   
 * Select Roles for “User Roles that can use filters”
    -  This reply was modified 3 years ago by [missveronica](https://wordpress.org/support/users/missveronicatv/).
 *  Thread Starter [den1sa](https://wordpress.org/support/users/den1sa/)
 * (@den1sa)
 * [3 years ago](https://wordpress.org/support/topic/conditional-or-step-filter/#post-16655722)
 * Thank you. I will give this a go.
 *  Thread Starter [den1sa](https://wordpress.org/support/users/den1sa/)
 * (@den1sa)
 * [3 years ago](https://wordpress.org/support/topic/conditional-or-step-filter/#post-16655782)
 * I have put everything in place.
 * When I go to the filter page and select Car, the dropdown doesnt filter to Car
   types. Do you know what I may have done wrong?
 * I have the Vehicle List (parent) which is static and always should appear. The
   variable fields are Cars, Boats, Planes, etc… and should only show up depending
   what value has been selected in the parent.
 * Maybe you can help me. Thanks.
 *  Thread Starter [den1sa](https://wordpress.org/support/users/den1sa/)
 * (@den1sa)
 * [3 years ago](https://wordpress.org/support/topic/conditional-or-step-filter/#post-16655913)
 * I have worked on the solution some more and now have the form fixed. Now when
   you select Car from the Vehicle List, the Vehicle Type list the car types. This
   also now works in the filter list.
 * Thank you MissVeronica for this solution, however, due to the structure of my
   data, rather than having one field that contains all the vehicle types, I have
   a separate field per vehicle type. So, one that contains all Car Types, another
   that contains all Van types, and so on…
 * So my question is how do I hide all the Vehicle Type fields and only show the
   correct Vehicle Type field (e.g. Car Types or Van Types, etc) based on the selection
   in the Vehicle List?
 *  Thread Starter [den1sa](https://wordpress.org/support/users/den1sa/)
 * (@den1sa)
 * [3 years ago](https://wordpress.org/support/topic/conditional-or-step-filter/#post-16657793)
 * Hi MissVeronica,
 * Thank you. Everything works.
 * Denis
    -  This reply was modified 3 years ago by [den1sa](https://wordpress.org/support/users/den1sa/).
    -  This reply was modified 3 years ago by [den1sa](https://wordpress.org/support/users/den1sa/).
    -  This reply was modified 3 years ago by [den1sa](https://wordpress.org/support/users/den1sa/).

Viewing 8 replies - 1 through 8 (of 8 total)

The topic ‘Conditional or Step Filter’ is closed to new replies.

 * ![](https://ps.w.org/ultimate-member/assets/icon-256x256.png?rev=3160947)
 * [Ultimate Member – User Profile, Registration, Login, Member Directory, Content Restriction & Membership Plugin](https://wordpress.org/plugins/ultimate-member/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/ultimate-member/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/ultimate-member/)
 * [Active Topics](https://wordpress.org/support/plugin/ultimate-member/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/ultimate-member/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/ultimate-member/reviews/)

 * 8 replies
 * 3 participants
 * Last reply from: [den1sa](https://wordpress.org/support/users/den1sa/)
 * Last activity: [3 years ago](https://wordpress.org/support/topic/conditional-or-step-filter/#post-16657793)
 * Status: resolved