• WPChina

    (@wordpresschina)


    I have 2 dropdowns, each with their own submit button, that let people go to different categories. I keep them separate because my site has 2 general groups of Categories: Group A deals with categories that are names of countries like USA, Canada, Mexico; and Group B deals with categories that are like “culture”, “food”, “news”.

    Therefore, one Post on my site might be in one category from Group A (i.e. USA) and then a category from Group B (i.e. “food”).

    Currently, I have the 2 separate groups of dropdowns, so this means a user can only see the Category of all the USA posts, or all the Food posts, etc.

    However, a user can not see all the posts that are both Food and USA when using the dropdown. I know that if they go to mydomain.com/category/usa/food they can see all the “USA” and “food” posts together, but I can’t figure how to combine the two dropdowns to deliver one URL.

    I do not want to have one dropdown that allows for multiple selections, because then I do not want people to choose both USA and Canada or Food and News — they must only choose 1 from Group A and 1 from Group B (or only 1 from Group A and nothing from Group B, or vice versa).

    Any ideas?

Viewing 7 replies - 1 through 7 (of 7 total)
  • How do you retrieve the categories for the dropdown? What code do you use?

    Thread Starter WPChina

    (@wordpresschina)

    I use static HTML because I can’t exclude categories using the built-in WordPress tags:

    <form action="<?php bloginfo('home'); ?>" method="get">
    <select name="cat" id="cat" class="postform">
    <option></option>
    	<option class="level-0" value="1">USA</option>
    	<option class="level-0" value="2">Canada</option>
    </select>
       <input name="submit" value="Search Country" type="submit">
       </form>
    <br />
    <form action="<?php bloginfo('home'); ?>" method="get">
    <select name="cat" id="cat" class="postform">
    <option></option>
    	<option class="level-0" value="10">Food</option>
    	<option class="level-0" value="11">News</option>
    </select>
       <input name="submit" value="Search" type="submit">
       </form>

    Use the examples described in the article, wp_dropdown_categories(), with something like:

    <?php wp_dropdown_categories('include=3,4&show_count=1&hierarchical=1'); ?>

    Where 3 and 4 are your category ID to ‘merge’.

    Thread Starter WPChina

    (@wordpresschina)

    Great! I somehow missed the ability to do an “include” of cats – I thought those were not possible. Ok I will test it today and get back with results.

    Thread Starter WPChina

    (@wordpresschina)

    Wait.. this does not solve the problem exactly.

    The problem, restated in another way, is this:

    I have Dropdown A with categories=1,2
    I have Dropdown B with categories=10,11

    So I have 2 separate dropdowns and I want to put 1 & 10 together, or 1 & 11, or 2 & 10, or 2 & 11. Basically one choice from Dropdown A and one choice from Dropdown B.

    Currently when I do this, the resulting URL shows something like cat=1&cat=10, but my goal is to get it to only show cat=1,10.

    Maybe Javascript is needed to join these? I’m not that strong in Javascript so unsure if that is the way to do this 🙁

    Thread Starter WPChina

    (@wordpresschina)

    Any ideas?

    I am looking for the exactly same thing.
    But I want to use wp_list_categories() instead of dropdowns.

    I thought I can filter category_link?!

    Any ideas appreciated too!

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘How to merge 2 categories dropdowns into 1 on WordPress?’ is closed to new replies.