M
M
Marina Smirnova2016-11-14 12:34:48
Taxonomy
Marina Smirnova, 2016-11-14 12:34:48

Custom Taxonomies - Dropdown List of Countries, Cities and Dates WordPress?

Good afternoon dear friends!
Please tell me some advice: how to implement a drop-down list of countries, cities and dates.
Actually, I implemented countries, cities, dates, but the question is:
1. A drop-down list of countries, select, for example, Russia, cities drop out in the next window, for example, Moscow, in the last window - months, for example, only active ones (for example, there are excursions only in January, March, August, and the rest of the months are not shown).
2. How to implement, if in the search form, when you simply click the Find button without applying filtering, all records from Countries, Cities, Months come out.
3. I don’t use plugins, I did it by adding arbitrary entries, like Countries, Cities, Months, only filters on them. The list of countries is small, only 10, about 30 cities, 12 months, years are not added.
Thank you very much!

Answer the question

In order to leave comments, you need to log in

2 answer(s)
I
Igor Vorotnev, 2016-11-14
@HeadOnFire

Make countries and cities nested taxonomy, dates metadata.
Next, the question will be to generate a url with all the selected parameters, and then, through the pre_get_posts hook, take these parameters using get_query_var () and modify the main query (enter tax_query for countries / cities and meta_query for dates).

M
Marina Smirnova, 2016-11-17
@99WEBDEV

Thank you, Igor, for the answer, I have this option:

<script type="text/javascript">
// Countries
var country_arr = new Array("Россия", "Украина", "Казахстан");

// States
var s_a = new Array();
s_a[0] = "";
s_a[1] = "Москва|С.-Петербург";
s_a[2] = "Киев|Одесса";
s_a[3] = "Астана";
s_a[4] = "Направление";


function populateStates(countryElementId, stateElementId) {

    var selectedCountryIndex = document.getElementById(countryElementId).selectedIndex;

    var stateElement = document.getElementById(stateElementId);

    stateElement.length = 0; // Fixed by Julian Woods
    stateElement.options[0] = new Option('Направление', '');
    stateElement.selectedIndex = 0;

    var state_arr = s_a[selectedCountryIndex].split("|");

    for (var i = 0; i < state_arr.length; i++) {
        stateElement.options[stateElement.length] = new Option(state_arr[i], state_arr[i]);
    }
}

function populateCountries(countryElementId, stateElementId) {

    var countryElement = document.getElementById(countryElementId);
    countryElement.length = 0;
    countryElement.options[0] = new Option('Страна', '-1');
    countryElement.selectedIndex = 0;
    for (var i = 0; i < country_arr.length; i++) {
        countryElement.options[countryElement.length] = new Option(country_arr[i], country_arr[i]);
    }

    if (stateElementId) {
        countryElement.onchange = function () {
            populateStates(countryElementId, stateElementId);
        };
    }
}

</script>

And the form itself:
<form action="<?php echo home_url ?>" method="get">
                  <label for="locations" ></label>
                  <select id="country" name="country"></select>
                   <label for="city"></label>
                  <select name="city" id="state"></select>

                   <label for="dates"></label>
                  <select name="dates" id="dates">
                   <option value="all" selected="selected">Выберите даты</option>
                    <option value="January">Январь</option>
                    <option value="February">Февраль</option>
                     <option value="March">Март</option>
                      <option value="April">Апрель</option>
                      <option value="May">Май</option>
                      <option value="June">Июнь</option>
                      <option value="July">Июль</option>
                       <option value="August">Август</option>
                       <option value="September">Сентябрь</option>
                        <option value="October">Октябрь</option>
                        <option value="November">Ноябрь</option>
                        <option value="December">Декабрь</option>
                  </select>
                  <input type="submit" name="submit" id="submit" value="Найти"></form>

And, adding a post, for example, Medical Exhibition, Russia, Moscow, October - the search gives me, but how to make the month of October only active in this case does not work.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question