• Resolved nadine00

    (@nadine00)


    Hello,

    I’m trying to make a drop down menu that acts like a filter for an archive. Basically I would like it, when selected to show all the posts in the option selected in the drop down + the cat ID I’m pulling before the drop down. Here’s what I have so far, I just don’t know how to work $cat into the bottom…

    <?php
    // get the first specific category to filter by
    $cat=get_cat_ID('Teacher\'s Lounge');
    echo $cat;
    ?>
    
    <?php
    //get the second category to filter by
    $args = array(
    'child_of'=> 44,
    'depth' => 1,
    )
    
    ?>
    
    <?php 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 get_option('home');?>/?cat="+dropdown.options[dropdown.selectedIndex].value;
    	}
        }
        dropdown.onchange = onCatChange;
    </script>

    My thought is that it’s something along the lines of:

    <?php echo get_option('home');?>/?cat="&&$cat+dropdown.options[dropdown.selectedIndex].value;

    but I am not sure of syntax.

    suggestions?

    Thank you.

    Nadine.

  • The topic ‘making an archive filter with a drop down, based on two categories’ is closed to new replies.