Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Contributor Champ Camba

    (@champsupertramp)

    Hi @snydez

    Could you please provide your custom code so we can review it and we’ll test it on our end?

    Regards,

    Thread Starter snydez

    (@snydez)

    hi @champsupertramp

    below is the code i use

    
    /*Write here your own functions */
    
    function custom_negara_dropdown() { 	
      $coutries = array( 
           "FR" => "France", 
           "ES" => "Spain" ,
    	   "ID" => "Indonesia",
      ); 		
      
      return $coutries;         
    }
    
    function custom_provinsi_dropdown( $has_parent = false ) {
    	
    	$parent_option = $_POST['parent_option'];
    	
    	$all_options = array(
    		"ID" => array(
    			"11" => "Aceh",
    			"12" => "Sumatera Utara",
    			"13" => "Sumatera Barat",
    			"14" => "Riau",
    			"15" => "Jambi",
    			"16" => "Sumatera Selatan",
    			"17" => "Bengkulu",
    			"18" => "Lampung",
    			"19" => "Kepulauan Bangka Belitung",
    			"21" => "Kepulauan Riau",
    			"31" => "DKI Jakarta",
    			"32" => "Jawa Barat",
    			"33" => "Jawa Tengah",
    			"34" => "DI Yogyakarta",
    			"35" => "Jawa Timur",
    			"36" => "Banten",
    			"51" => "Bali",
    			"52" => "Nusa Tenggara Barat",
    			"53" => "Nusa Tenggara Timur",
    			"61" => "Kalimantan Barat",
    			"62" => "Kalimantan Tengah",
    			"63" => "Kalimantan Selatan",
    			"64" => "Kalimantan Timur",
    			"65" => "Kalimantan Utara",
    			"71" => "Sulawesi Utara",
    			"72" => "Sulawesi Tengah",
    			"73" => "Sulawesi Selatan",
    			"74" => "Sulawesi Tenggara",
    			"75" => "Gorontalo",
    			"76" => "Sulawesi Barat",
    			"81" => "Maluku",
    			"82" => "Maluku Utara",
    			"91" => "Papua Barat",
    			"94" => "Papua",
    		),
    		 "FR" => array(
             	"Paris" =>"Paris",
             	"Marseille" => "Marseille",
             	"Lyon" => "Lyon",
          	),
    	);
    	
    	$arr_options = array();
    	
    	if ( ! is_array( $parent_options ) ) {
          $parent_options = array( $parent_options );
       	}
    
        if( isset( $all_options[ $parent_option ] ) ){
    		$arr_options = $all_options[ $parent_option ];
    	}elseif( ! isset( $_POST['parent_option'] ) ) {
    
    		foreach( $all_options as $k => $opts ){
    			$arr_options = array_merge( $opts, $arr_options );
    		}
    
    	}
    
    	return $arr_options;
    	
    }
    
    function custom_kota_dropdown( $has_parent = false ){
    	$parent_option = $_POST['parent_option'];
    	
    	$all_options = array(
    		"11" => array(
    			"1101" => "Simeulue",
    			"1102" => "Aceh Singkil",
    			"1103" => "Aceh Selatan",
    			"1104" => "Aceh Tenggara",
    			"1105" => "Aceh Timur",
    			"1106" => "Aceh Tengah",
    			"1107" => "Aceh Barat",
    			"1108" => "Aceh Besar",
    			"1109" => "Pidie",
    			"1110" => "Bireuen",
    			"1111" => "Aceh Utara",
    			"1112" => "Aceh Barat Daya",
    			"1113" => "Gayo Lues",
    			"1114" => "Aceh Tamiang",
    			"1115" => "Nagan Raya",
    			"1116" => "Aceh Jaya",
    			"1117" => "Bener Meriah",
    			"1118" => "Pidie Jaya",
    			"1171" => "Banda Aceh",
    			"1172" => "Sabang",
    			"1173" => "Langsa",
    			"1174" => "Lhokseumawe",
    			"1175" => "Subulussalam",
    		),
    		"31" => array(
    			"3101" => "Kepulauan Seribu",
    			"3171" => "Jakarta Selatan",
    			"3172" => "Jakarta Timur",
    			"3173" => "Jakarta Pusat",
    			"3174" => "Jakarta Barat",
    			"3175" => "Jakarta Utara",
    		),
    		"37" => array(
    			"3201" => "Bogor",
    			"3202" => "Sukabumi",
    			"3203" => "Cianjur",
    			"3204" => "Bandung",
    			"3205" => "Garut",
    			"3206" => "Tasikmalaya",
    			"3207" => "Ciamis",
    			"3208" => "Kuningan",
    			"3209" => "Cirebon",
    			"3210" => "Majalengka",
    			"3211" => "Sumedang",
    			"3212" => "Indramayu",
    			"3213" => "Subang",
    			"3214" => "Purwakarta",
    			"3215" => "Karawang",
    			"3216" => "Bekasi",
    			"3217" => "Bandung Barat",
    			"3218" => "Pangandaran",
    			"3271" => "Bogor",
    			"3272" => "Sukabumi",
    			"3273" => "Bandung",
    			"3274" => "Cirebon",
    			"3275" => "Bekasi",
    			"3276" => "Depok",
    			"3277" => "Cimahi",
    			"3278" => "Tasikmalaya",
    			"3279" => "Banjar",
    		),
    	);
    	
    	$arr_options = array();
    		
    
    	if( isset( $all_options[ $parent_option ] ) ){
    		$arr_options = $all_options[ $parent_option ];
    	}elseif( ! isset( $_POST['parent_option'] ) ) {
    
    		foreach( $all_options as $k => $opts ){
    			$arr_options = array_merge( $opts, $arr_options );
    		}
    
    	}
    
    	return $arr_options;
    }
    

    and the screenshot of the form
    https://s4.gifyu.com/images/negara-202104081044.png
    https://s4.gifyu.com/images/provinsi-202104081045.png
    https://s4.gifyu.com/images/kota-202104081045.png

    thank you for your attention and assistance.

    • This reply was modified 3 years, 11 months ago by snydez.
    Plugin Author Mykyta Synelnikov

    (@nsinelnikov)

    Hi @snydez

    Please try to use this code below:

    /*Write here your own functions */
    
    function custom_negara_dropdown() {
    	$coutries = array(
    		"FR" => "France",
    		"ES" => "Spain" ,
    		"ID" => "Indonesia",
    	);
    
    	return $coutries;
    }
    
    function custom_provinsi_dropdown( $has_parent = false ) {
    
    	$parent_options = isset( $_POST['parent_option'] ) ? $_POST['parent_option'] : false;
    
    	$all_options = array(
    		"ID" => array(
    			"Aceh" => "Aceh",
    			"Sumatera Utara" => "Sumatera Utara",
    			"Sumatera Barat" => "Sumatera Barat",
    			"Riau" => "Riau",
    			"Jambi" => "Jambi",
    			"Sumatera Selatan" => "Sumatera Selatan",
    			"Bengkulu" => "Bengkulu",
    			"Lampung" => "Lampung",
    			"Kepulauan Bangka Belitung" => "Kepulauan Bangka Belitung",
    			"Kepulauan Riau" => "Kepulauan Riau",
    			"DKI Jakarta" => "DKI Jakarta",
    			"Jawa Barat" => "Jawa Barat",
    			"Jawa Tengah" => "Jawa Tengah",
    			"DI Yogyakarta" => "DI Yogyakarta",
    			"Jawa Timur" => "Jawa Timur",
    			"Banten" => "Banten",
    			"Bali" => "Bali",
    			"Nusa Tenggara Barat" => "Nusa Tenggara Barat",
    			"Nusa Tenggara Timur" => "Nusa Tenggara Timur",
    			"Kalimantan Barat" => "Kalimantan Barat",
    			"Kalimantan Tengah" => "Kalimantan Tengah",
    			"Kalimantan Selatan" => "Kalimantan Selatan",
    			"Kalimantan Timur" => "Kalimantan Timur",
    			"Kalimantan Utara" => "Kalimantan Utara",
    			"Sulawesi Utara" => "Sulawesi Utara",
    			"Sulawesi Tengah" => "Sulawesi Tengah",
    			"Sulawesi Selatan" => "Sulawesi Selatan",
    			"Sulawesi Tenggara" => "Sulawesi Tenggara",
    			"Gorontalo" => "Gorontalo",
    			"Sulawesi Barat" => "Sulawesi Barat",
    			"Maluku" => "Maluku",
    			"Maluku Utara" => "Maluku Utara",
    			"Papua Barat" => "Papua Barat",
    			"Papua" => "Papua",
    		),
    		"FR" => array(
    			"Paris" =>"Paris",
    			"Marseille" => "Marseille",
    			"Lyon" => "Lyon",
    		),
    	);
    
    	$arr_options = array();
    
    	if ( ! is_array( $parent_options ) ) {
    		$parent_options = array( $parent_options );
    	}
    
    	$arr_options = array();
    	foreach ( $parent_options as $key => $parent_option ) {
    
    		if ( isset( $all_options[ $parent_option ] ) ) {
    			$arr_options = array_merge( $arr_options, $all_options[ $parent_option ] );
    		} elseif ( ! isset( $_POST['parent_option'] ) ) {
    			foreach ( $all_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 states";
    	} else {
    		$arr_options = array_unique( $arr_options );
    	}
    
    	return $arr_options;
    }
    
    function custom_kota_dropdown( $has_parent = false ){
    	$parent_options = isset( $_POST['parent_option'] ) ? $_POST['parent_option'] : false;
    
    	$all_options = array(
    		"Aceh" => array(
    			"Simeulue" => "Simeulue",
    			"Aceh Singkil" => "Aceh Singkil",
    			"Aceh Selatan" => "Aceh Selatan",
    			"Aceh Tenggara" => "Aceh Tenggara",
    			"Aceh Timur" => "Aceh Timur",
    			"Aceh Tengah" => "Aceh Tengah",
    			"Aceh Barat" => "Aceh Barat",
    			"Aceh Besar" => "Aceh Besar",
    			"Pidie" => "Pidie",
    			"Bireuen" => "Bireuen",
    			"Aceh Utara" => "Aceh Utara",
    			"Aceh Barat Daya" => "Aceh Barat Daya",
    			"Gayo Lues" => "Gayo Lues",
    			"Aceh Tamiang" => "Aceh Tamiang",
    			"Nagan Raya" => "Nagan Raya",
    			"Aceh Jaya" => "Aceh Jaya",
    			"Bener Meriah" => "Bener Meriah",
    			"Pidie Jaya" => "Pidie Jaya",
    			"Banda Aceh" => "Banda Aceh",
    			"Sabang" => "Sabang",
    			"Langsa" => "Langsa",
    			"Lhokseumawe" => "Lhokseumawe",
    			"Subulussalam" => "Subulussalam",
    		),
    		"DKI Jakarta" => array(
    			"Kepulauan Seribu" => "Kepulauan Seribu",
    			"Jakarta Selatan" => "Jakarta Selatan",
    			"Jakarta Timur" => "Jakarta Timur",
    			"Jakarta Pusat" => "Jakarta Pusat",
    			"Jakarta Barat" => "Jakarta Barat",
    			"Jakarta Utara" => "Jakarta Utara",
    		),
    		"Jawa Barat" => array(
    			"Bogor" => "Bogor",
    			"Sukabumi" => "Sukabumi",
    			"Cianjur" => "Cianjur",
    			"Bandung" => "Bandung",
    			"Garut" => "Garut",
    			"Tasikmalaya" => "Tasikmalaya",
    			"Ciamis" => "Ciamis",
    			"Kuningan" => "Kuningan",
    			"Cirebon" => "Cirebon",
    			"Majalengka" => "Majalengka",
    			"Sumedang" => "Sumedang",
    			"Indramayu" => "Indramayu",
    			"Subang" => "Subang",
    			"Purwakarta" => "Purwakarta",
    			"Karawang" => "Karawang",
    			"Bekasi" => "Bekasi",
    			"Bandung Barat" => "Bandung Barat",
    			"Pangandaran" => "Pangandaran",
    			"Depok" => "Depok",
    			"Cimahi" => "Cimahi",
    			"Banjar" => "Banjar",
    		),
    	);
    
    	$arr_options = array();
    
    	if ( ! is_array( $parent_options ) ) {
    		$parent_options = array( $parent_options );
    	}
    
    	$arr_options = array();
    	foreach ( $parent_options as $key => $parent_option ) {
    
    		if ( isset( $all_options[ $parent_option ] ) ) {
    			$arr_options = array_merge( $arr_options, $all_options[ $parent_option ] );
    		} elseif ( ! isset( $_POST['parent_option'] ) ) {
    			foreach ( $all_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 states";
    	} else {
    		$arr_options = array_unique( $arr_options );
    	}
    
    	return $arr_options;
    }

    Just please make sure that you have set the provinsi in usermeta with not numeric values e.g. ‘Aceh’

    Best Regards!

    Plugin Contributor Champ Camba

    (@champsupertramp)

    Hey there!

    This thread has been inactive for a while so we’re going to go ahead and mark it Resolved.

    Please feel free to re-open this thread by changing the Topic Status to ‘Not Resolved’ if any other questions come up and we’d be happy to help. ??

    Regards,

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘How to filter using Choices Callback and Parent Option’ is closed to new replies.