<?php echo '<div class="row">'; $args = array('orderby' => 'count', 'hide_empty' => false, 'parent' => 0); $terms = get_terms(array('city-type'), $args); if (!empty($terms)) { $selected_other = ''; if (!empty($othertextonomies)) { $selected_other = "selected=selected"; } echo '<div class="col-md-4 col-sm-4 cities">'; echo '<select name="textonomies_city[]" data-city-type-value="' . $city_type_value . '" data-last-select_value="" data-id="parent_city" class="textonomies_city form-control margin-0 selectpicker">'; echo '<option value="city">' . __('City', 'framework') . '</option>'; $city_current_id = get_term_by('slug', $city_type_value, 'city-type'); $parent_id = ''; if (!empty($city_current_id)) { $data = get_term_top_most_parent($city_current_id->term_id, 'city-type'); $parent_id = $data->term_id; } foreach ($terms as $term_data) { echo "<option value='" . $term_data->slug . "' " . selected($parent_id, $term_data->term_id, false) . ">" . $term_data->name . "</option>"; } echo '<option value ="other" ' . $selected_other . '>' . __('Other', 'framework') . '</option>'; echo '</select>'; echo '</div>'; } // use for provide othertextonomies meta id in js echo '<span class ="othertextonomies_meta" id="' . $othertextonomies . '"></span>'; if (!empty($data)) { echo '<span class ="sub_sub_category_id" id="' . $city_current_id->term_id . '"></span>'; } echo '</div>';
function property_sub_cities_at_start() { $subcities_html = ''; $last_select_value = "last_select"; if (isset($_POST['othertextonomies_meta']) && !empty($_POST['othertextonomies_meta'])) { $othertextonomies_meta = $_POST['othertextonomies_meta']; $subcities_html .= '<div class="col-md-4 col-sm-4"><input type="text" name="othertextonomies" value ="' . $othertextonomies_meta . '" class ="form-control othertextonomies margin-0" placeholder="Enter city name"></div>'; } if (isset($_POST['sub_sub_category_id']) && !empty($_POST['sub_sub_category_id'])) { $sub_sub_category_id = $_POST['sub_sub_category_id']; $city_current_id = get_term_by('term_id', $sub_sub_category_id, 'city-type'); $second_parent = get_term_by('term_id', $sub_sub_category_id, 'city-type'); $sub_sub_parent_id = $city_current_id->parent; $data = get_term_top_most_parent($sub_sub_category_id, 'city-type'); $parent_category_id = $data->term_id; while ($second_parent->parent != $parent_category_id) { $second_parent = get_term_by('id', $second_parent->parent, 'city-type'); $sub_sub_parent_id = $second_parent->term_id; } if ($parent_category_id != $sub_sub_parent_id) { $var_parenr_child_arg = 'child_of'; $last_select_value = 'last_select'; } else { $var_parenr_child_arg = 'parent'; $last_select_value = ''; } if (!empty($parent_category_id) && !empty($sub_sub_parent_id) && $parent_category_id != $sub_sub_parent_id) { $args = array('orderby' => 'count', 'hide_empty' => false, 'parent' => $parent_category_id); $terms = get_terms(array('city-type'), $args); if (count($terms) > 0) { $city_type_value = ''; $subcities_html = '<div class="sub_child_show col-md-4 col-sm-4"><select name="textonomies_city[]" data-city-type-value="' . $city_type_value . '" data-last-select_value="' . $last_select_value . '" data-id="subcity" class="textonomies_subcity form-control margin-0 selectpicker"><option value="">' . __('Sub City', 'framework') . '</option>'; foreach ($terms as $term_data) { $subcities_html .= "<option value='" . $term_data->slug . "' " . selected($sub_sub_parent_id, $term_data->term_id, false) . ">" . $term_data->name . "</option>"; } $subcities_html .= '</select></div>'; } } if (!empty($sub_sub_parent_id)) { $args_sub = array('orderby' => 'count', 'hide_empty' => false, $var_parenr_child_arg => $sub_sub_parent_id); $terms = get_terms(array('city-type'), $args_sub); if (count($terms) > 0) { $city_type_value = ''; $subcities_html .= '<div class="sub_child_show col-md-4 col-sm-4"><select name="textonomies_city[]" data-city-type-value="' . $city_type_value . '" data-last-select_value="' . $last_select_value . '" data-id="subcity" class="textonomies_subcity form-control margin-0 selectpicker"><option value="">' . __('Sub City', 'framework') . '</option>'; foreach ($terms as $term_data) { $subcities_html .= "<option value='" . $term_data->slug . "' " . selected($sub_sub_category_id, $term_data->term_id, false) . ">" . $term_data->name . "</option>"; } $subcities_html .= '</select></div>'; } } } echo $subcities_html; die; }