Duplicate taxonomy dropdown wordpress

Asked

Viewed 23 times

1

I followed this tutorial https://clicknathan.com/web-design/wordpress-custom-taxonomy-dropdown-without-a-submit-button/ , which is working perfectly, except because when I try to add 2 dropdown from 2 different taxonomy, a bug occurs and nothing else works. What I must do to make it work?

*I already changed the names of the ID’s and JS variables, and it didn’t work.

Follow my changed code.

Thank you.

<?php $args = array(
    'show_option_all' => 'UF',
    'taxonomy' => 'estado',
    'walker' => new categoryDropdown
);

wp_dropdown_categories( $args );
?>

<script type="text/javascript"><!--
    var dropdownEstado = document.getElementById("cat-estado");
    function onCatEstadoChange() {

        if ( dropdownEstado.options[dropdownEstado.selectedIndex].value != '0' ) {
            location.href = "<?php echo esc_url( home_url( '/' ) ); ?>/?estado="+dropdownEstado.options[dropdownEstado.selectedIndex].value;
        }
    }

    dropdownEstado.onchange = onCatEstadoChange;
--></script>
<?php $args = array(
    'show_option_all' => 'Tipo',
    'taxonomy' => 'tipo',
    'walker' => new categoryDropdownEstado
);

wp_dropdown_categories( $args ); ?>
<script type="text/javascript"><!--
    var dropdown = document.getElementById("cat");
    function onCatChange() {

        if ( dropdown.options[dropdown.selectedIndex].value != '0' ) {
            location.href = "<?php echo esc_url( home_url( '/' ) ); ?>/?tipo="+dropdown.options[dropdown.selectedIndex].value;
        }
    }
    dropdown.onchange = onCatChange;
--></script>
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.