• Need a help! For several days looking for a solution.

    This is my code:
    <table border=”0″ cellspacing=”0″ width=”100%” id=”poisk”>
    <form action=”<?php bloginfo(‘url’); ?>” method=”get”>
    <tr>
    <td><?php wp_dropdown_categories(‘show_option_none=1&child_of=25&orderby=name’); ?></td>
    <td><?php wp_dropdown_categories(‘show_option_none=2&child_of=30&orderby=name’); ?></td>
    <td><?php wp_dropdown_categories(‘show_option_none=Р3&child_of=15&orderby=name’); ?></td>
    <td><input type=”submit” name=”submit” value=”Show” /></td>
    </tr>
    </form>
    </table>

    But the problem is showing posts only from last categoy (child_of=15) when submiting!

Viewing 9 replies - 1 through 9 (of 9 total)
  • Thread Starter doronov

    (@doronov)

    Need a help! For several days looking for a solution.

    This is my code:

    <table border="0" cellspacing="0" width="100%" id="poisk">
    <form action="<?php bloginfo('url'); ?>" method="get">
    <tr>
    <td><?php wp_dropdown_categories('show_option_none=1&child_of=25&orderby=name'); ?></td>
    <td><?php wp_dropdown_categories('show_option_none=2&child_of=30&orderby=name'); ?></td>
    <td><?php wp_dropdown_categories('show_option_none=Р3&child_of=15&orderby=name'); ?></td>
    <td><input type="submit" name="submit" value="Show" /></td>
    </tr>
    </form>
    </table>

    But the problem is showing posts only from last categoy (child_of=15) when submiting!

    Well, I can see at least one syntax mistake. From the codex for wp_dropdown_categories() it states the the function of show_option_none is:

    show_option_none
    (string) Causes the HTML for the drop-down to allow you to select NONE of the categories.

    But you have assigned values of 1, 2 and P3 to it?

    Try:

    <td><?php wp_dropdown_categories('show_option_none=&child_of=25&orderby=name'); ?></td>
    <td><?php wp_dropdown_categories('show_option_none=&child_of=30&orderby=name'); ?></td>
    <td><?php wp_dropdown_categories('show_option_none=&child_of=15&orderby=name'); ?></td>

    Also, to make sure that you don’t have issues with your category numerical ids, why don’t you consider using get_cat_id()?

    Now that I actually look at what you are doing – the answer is no, you cannot achieve this. You are trying to and together a whole bunch of categories and only get posts in those. First, the way you are doing it will only yield the last select, as you have multiple selects in one form.

    Thread Starter doronov

    (@doronov)

    Thank you Clementsm!

    1. show_option_none – is ok, Ill check it.
    2. I found a soulution, where some guys suggest just to change name and class in each category and it will work (by default they are cat and postform). But it isnt, becouse, when I change the name its stop working (doesnot filtering ) and ID is still the same. I dont know how to change ID.

    When you print out the dropdowns you’re essentially creating 3 boxes, where each is over-writing the functionality for the previous..

    <select name="cat">
    ...more code
    <select name="cat">
    ...more code
    <select name="cat">

    If you want them to function seperately you’ll need to assign them different “name”s which will in turn give you different POST or GET vars.

    You’ll have to deal with the data on the receiving end to, if that makes no sense whatsoever, then the short answer is, you can’t have 3 with the same name do seperate things.. (at least not without some re-coding)..

    Thread Starter doronov

    (@doronov)

    <form action="<?php bloginfo('url'); ?>" method="get">
    <?php wp_dropdown_categories('child_of=25&orderby=name&name=cat1&class=post1'); ?>
    <?php wp_dropdown_categories('child_of=30&orderby=name&name=cat2&class=post2'); ?>
    <?php wp_dropdown_categories('child_of=15&orderby=name&name=cat3&class=post3'); ?>
    <input type="submit" name="submit" value="view" />
    </form>

    When Im changing the name, its not working anymore. Im confusing!

    I think you are forgetting how html forms work, quick refresher, without all the WordPress template tags:

    <form action="myaction.php" method="get">
    <select name="cat" id="my_unique_select" class="my_select_class">
    	<option class="level-0" value="13">Category 1</option>
    	<option class="level-0" value="14">Category 2</option>
    	<option class="level-0" value="15">Category 3</option>
    	<option class="level-0" value="16">Category 4</option>
    </select>
    <input type="submit" name="submit" value="submit" />
    </form>

    This is how an HTML drop down form is supposed to be coded. The script “myaction.php” is expecting to be called with a GET method, and is expecting the get to be formulated as follows:

    myaction.php?cat=15

    The attribute “cat” comes from the name attribute of the select, and the number 15 is the value of the selected option of the select when the submit button is pressed.

    So, moving on to what you are doing (again minus all the WordPress template tags for clarity):

    <form action="myaction.php" method="get">
    <select name="cat" id="my_unique_select" class="my_select_class">
    	<option value="13">Category 1</option>
    	<option value="14">Category 2</option>
    	<option value="15">Category 3</option>
    	<option value="16">Category 4</option>
    </select>
    <select name="cat" id="my_unique_select" class="my_select_class">
    	<option value="23">Category 11</option>
    	<option value="24">Category 12</option>
    	<option value="25">Category 13</option>
    	<option value="26">Category 14</option>
    </select>
    <select name="cat" id="my_unique_select" class="my_select_class">
    	<option value="33">Category 21</option>
    	<option value="34">Category 22</option>
    	<option value="35">Category 23</option>
    	<option value="36">Category 24</option>
    </select>
    <input type="submit" name="submit" value="submit" />
    </form>

    lets say you have selected one option in each select. When you press submit, only the value of the last select option will be sent to “myaction.php” with a GET method. Changing the name of the selects, will result in a larger GET method, but myaction.php won’t magically know what to do with the new names, as it only understands what to do with “cat=something” in the get method. Thus what you are trying to do wont work, as you also need to modify “myaction.php” and tell it what to do with multiple select inputs.

    Since “myaction.php” is a part of your program – in this case WordPress, you probably don’t want to mess with it.

    That said, there are a number of enhanced search plugins available that can do boolean searches on categories. Checkout this one on the plugin page for example…

    Thread Starter doronov

    (@doronov)

    Thank you very much, dear clementsm! You are great! ))

    I just found suitable plugin!

    Of course bear in mind (if i remember correctly), the name attribute won’t always be used as the identifier, i believe this is going to change in the future and form elements will be expected to use the id attribute instead…

    Now if only i could remember where i read that.. W3C maybe, could be wrong ..

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Multiple wp_dropdown_categories’ is closed to new replies.