SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Zealot
    Join Date
    Nov 2005
    Location
    Huntington Beach, CA
    Posts
    115
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Custom taxonomy filter

    I need to do is to create a filter based on this new taxonomy. I need to do this with drop down boxes.

    Here is an example of my custom taxonomy will be:

    - Artlcles
    --- Article 1
    --- Article 2
    --- Article 3
    - Amendments
    --- Amendment 1
    --- Amendment 2
    --- Amendment 3

    What I need is to have 2 drop down boxes. The first one will have all of the top level categories (Articles, Amendments, etc...) and then when one of those is selected it will populate/make appear a second drop down with all of the subcategories.

    I have put the following code together and maybe someone can help me figure out the last piece of the puzzle. You can also see what is happening at the URL http://www.constitutingamerica.org/dev2/

    PHP Code:
    <?php $args = array(
        
    'show_option_all'    => '',
        
    'show_option_none'   => '',
        
    'orderby'            => 'ID',
        
    'order'              => 'ASC',
        
    'show_count'         => 1,
        
    'hide_empty'         => 1,
        
    'child_of'           => 0,
        
    'parent'             => 0,
        
    'exclude'            => '',
        
    'echo'               => 1,
        
    'selected'           => 0,
        
    'hierarchical'       => 0,
        
    'name'               => 'cat',
        
    'id'                 => '',
        
    'class'              => 'postform',
        
    'depth'              => 1,
        
    'tab_index'          => 0,
        
    'taxonomy'           => 'classification',
        
    'hide_if_empty'      => false,
        
    'walker'             => ''
    );

    $tax_menu_items get_categories$args ); ?>

    <form name="class-filter" method="get" >
    <select name="class-dropdown" onchange="document.location.href=this.options[this.selectedIndex].value;">
    <option value="">Select</option>
    <? foreach ( $tax_menu_items as $tax_menu_item ): ?>
        <option value="<?php echo get_term_link($tax_menu_item,$tax_menu_item->taxonomy); ?>"><?php echo $tax_menu_item->name?></option>
    <?php endforeach; ?>
    </select>
    <?php

    $sub_tax_id 
    $wp_query->get_queried_object_id();
    if(
    $wp_query->get_queried_object_id()) {
    $args2 = array(
        
    'show_option_all'    => '',
        
    'show_option_none'   => '',
        
    'orderby'            => 'ID',
        
    'order'              => 'ASC',
        
    'show_count'         => 1,
        
    'hide_empty'         => 1,
        
    'child_of'           => 0,
        
    'parent'             => $sub_tax_id,
        
    'exclude'            => '',
        
    'echo'               => 1,
        
    'selected'           => 0,
        
    'hierarchical'       => 0,
        
    'name'               => 'cat2',
        
    'id'                 => '',
        
    'class'              => 'postform',
        
    'depth'              => 1,
        
    'tab_index'          => 0,
        
    'taxonomy'           => 'classification',
        
    'hide_if_empty'      => true,
        
    'walker'             => ''
    );

    $tax_menu_items2 get_categories$args2 ); ?>

    <select name="class-dropdown2" onchange="document.location.href=this.options[this.selectedIndex].value;" >
    <option value="">Select</option>
    <? foreach ( $tax_menu_items2 as $tax_menu_item2 ): ?>
        <option value="<?php echo get_term_link($tax_menu_item2,$tax_menu_item2->taxonomy); ?>"><?php echo $tax_menu_item2->name?></option>
    <?php endforeach; ?>
    </select>
    <? ?>
    </form>
    The only thing I need to figure out is how to keep the second drop down menu populated once it has been selected. Any ideas?
    Rob
    Pier Marketing ◄ Printing and Marketing Collateral - Order Online
    Pier Technologies ◄ Web Development & IT Solutions
    And That's News? ◄ My NEW Blog!!

  2. #2
    SitePoint Addict
    Join Date
    Oct 2008
    Location
    Virtual World is my location
    Posts
    316
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    The easiest option according to me would be to pass a variable along with the URL and select the sub category based on that.

    Second option is to get the URL and populate based on that. For example your url has the words /classification/the-constitution/ so for the constitution you could use the text and populate the sub categories as per the URL.
    FreelanceNext.com - Freelance Projects / Jobs & more...
    BargainNext.com - coupons / deals / bargains / offers & more...

  3. #3
    SitePoint Zealot
    Join Date
    Nov 2005
    Location
    Huntington Beach, CA
    Posts
    115
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by jaagare View Post
    The easiest option according to me would be to pass a variable along with the URL and select the sub category based on that.

    Second option is to get the URL and populate based on that. For example your url has the words /classification/the-constitution/ so for the constitution you could use the text and populate the sub categories as per the URL.
    Thank you for the reply. So instead of checking to see if a query has already been done I should check to see if the URL slug is selected? How can I grab the correct URL slug to do this?
    Rob
    Pier Marketing ◄ Printing and Marketing Collateral - Order Online
    Pier Technologies ◄ Web Development & IT Solutions
    And That's News? ◄ My NEW Blog!!

  4. #4
    SitePoint Zealot
    Join Date
    Nov 2005
    Location
    Huntington Beach, CA
    Posts
    115
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I was looking through my code more and testing it out on the link I posted http://www.constitutingamerica.org/dev2/. The first drop down box does not change which is what I want. The second box just clears its results. What I think is happening is that the second box is dependent on the $wp_query->get_queried_object_id(); variable I am grabbing to populate the second drop down. So when the second box is changed it is looking for children of the last query. To keep the results in the second box I need to grab the ID of the custom taxonomy that is selected in the first box. I have tried a bunch of different variables from the first half of the code that creates the first box but nothing seems to stick.

    Any ideas on what I can grab from that first code to keep that second box populated with all of the child results?
    Rob
    Pier Marketing ◄ Printing and Marketing Collateral - Order Online
    Pier Technologies ◄ Web Development & IT Solutions
    And That's News? ◄ My NEW Blog!!


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •