I
I
Ivan Shulga2021-07-17 18:28:46
WordPress
Ivan Shulga, 2021-07-17 18:28:46

How to hook up ajax to wp_dropdown_categories()?

<aside>
                    <p>Город:</p>
                    <div id="select">

                        <?php wp_dropdown_categories(array(
                            'show_option_none' => "Выберите город",
                            'hierarchical' => 1,
                            'child_of' => 6,
                            'depth' => 1
                        )); ?>

                        <script>
                            var dropdown = document.getElementById("cat");

                            function onCatChange() {
                                if (dropdown.options[dropdown.selectedIndex].value > 0) {
                                    location.href = "<?php echo get_option('home');
                                    ?>/?cat=" + dropdown.options[dropdown.selectedIndex].value;
                                }
                            }
                            dropdown.onchange = onCatChange;
                        </script>

                    </div>
                </aside>
                <div class="vacancy-section">

                    <?php while (have_posts()) : the_post(); ?>

                        <!--Карточка поста-->

                    <?php endwhile; // end of the loop. 
                    ?>

                </div>

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question