1

I am trying to filter child drop-down inputs based on parent dropdown. For example, if I select a state I need to show the cities only in the selected state. What I have done so far is added this below function in the functions.php file.

function getCities() {
//get the value from the 'parent' field, sent via the AJAX post.
$choice = $_POST['choose_mavatam1'];

  switch($choice) {
    case "Tamilnadu":
      $cities = [
        "Chennai" =>"Chennai",

      ];
      break;
    case "Karnataka":
      $cities = [
        "Bangalore"=>"Bangalore",

      ];
      break;
    default:
      //code to do something if other options are not selected (throw an error, or set $cities to a default array)
      $cities = ["no city"];

  }
return $cities;
}

I called this below function in Choices Callback field of ultimate member plugin for the parent field. The bug I face is the Edit Choices becomes this switch case's default value automatically as no city when I used this callback function.

1 Answer 1

1

In your code you can replace:

$choice = $_POST['choose_mavatam1'];

with this:

$choice = $_POST['parent_option'];

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.