• I’m making a simple directory site that only contains 1 store-type across multiple locations. The user should be able to choose from dropdowns:

    Region > District > [Submit]: Result=Shops in that District.
    (Note, the District should be optional; the user should be able to see the results from all Regions.)

    So basically it’s:
    [Parent Category] > [Sub-Categories of selected Parent] > [Posts in selected Sub-Category]

    So what I need is to show a Dropdown List of all my Parent Categories.
    Then, the second list should be Dynamically populated with the Sub-Category of the Parent. I say Dynamically because this list will grow as more shop locations are added.

    Then when the user selects their District, they will be shown a list of the Posts (shops) in that District. Ideally this will be shown on the same page.

    I hope that makes sense. Can anyone help me out?

Viewing 10 replies - 1 through 10 (of 10 total)
  • I’m assuming this is a custom post type? I’ve not tried this plugin but maybe a widget like this could work. https://www.ads-software.com/extend/plugins/list-custom-taxonomy-widget/

    Thread Starter dabhandconz

    (@dabhandconz)

    Thanks, but that doesn’t actually do what I need it to.

    It will let me create two dropdowns, in the form of 2 Widgets, but the 2 aren’t related in any way, so changing the Region on the first doesn’t automatically change to the corresponding list of Districts on the other.

    Think of it like choosing State and then Cities in that State. And then you’re shown a list of book stores in the chosen City.

    Also, no, these aren’t Custom Post Types, they’re just regular old Posts. Like I said, it’s a very simple site. In theory.

    So you are talking about two dropdowns? The second one is dependent on the first one? Something like this could be done with a paid plugin called gravityforms but I’m not aware of a free plugin that will do it. The other suggestion would be custom code of course.

    Thread Starter dabhandconz

    (@dabhandconz)

    Yep, exactly, I’m talking about using 2 Dropdowns; the Options in the second one the SubCategory list of the Category in the first one.

    So if you choose something like, California in the first dropdown, then the second would contain Los Angeles, San Franciso, etc.
    Choose New York in the first and the second would contain Albany, Buffalo, etc.

    You would then choose your city, eg. Buffalo, and then the results would be the stores (Posts) in Buffalo.

    I actually bought Gravity Forms a few hours ago because I thought it could do this. It does handle the dropdowns well, but I can’t get it to then display the resulting Posts based on the user’s selection. It seems like it can only display pre-determined results that you select when you create the form; It can’t dynamically serve up a result. Or if it can I can’t see how.

    [EDIT]
    Just to add something, I’ve played around but I can’t figure out how to write code to do this. It feels like it should be easy but it’s beyond me.

    You can use conditional code to display certain dropdowns. You may want to check their support forums for further help.

    Thread Starter dabhandconz

    (@dabhandconz)

    Geting Gravity Forms to display the conditional second dropdown was easy; it’s just that I don’t think it can then serve up dynamic results.

    It should be possible to handcode this; a lot of the elements are there.

    – I can display a dropdown list of Categories
    – There is a conditional tag for “in_category”
    – It’s possible to show Posts for a specific category based on ID.

    What I’m missing is “in_category” needs to refer to the Category ID selected in the first dropdown.
    If I could somehow grab the Category ID of the selected Parent item in the first dropdown, then I can ask the second dropdown to show Child Categories belonging to that Parent.

    And then once an item is selected in the second dropdown, I can use _its_ ID and pull posts from that specific Category.

    I just need a way to get the ID of a selected Category item in a dropdown.

    I’m on the go and don’t have time to try and code something up but again, gravity forms support is pretty quick and I would not be shocked if it could not be done through them. Post a question I’m their forum.

    Thread Starter dabhandconz

    (@dabhandconz)

    Yeah I did, thanks for the suggestions.

    Nick Halsey

    (@celloexpressions)

    You should use the wp_dropdown_categories() function: https://codex.www.ads-software.com/Function_Reference/wp_dropdown_categories.

    Specify the “child of” argument as the id of the parent category (dynamically, with the results of the first – this would need to re-run through php, but perhaps some ajax or a two-step process will work). That’s the best way to show only the children of a category in a dropdown. If hierarchical is set to true, you can hide all of the sub-children and sub-sub-children with css at any step in the process.

    I actually managed to get multiple dropdowns to work with gravity forms. Using the “conditional formatting” for example
    so with this structure Continent>Country>State>County
    In this example layout I’ll use Broome County, New York as my target

    1. Dropdown 1 = list Top level Categories. In this case “Continents”
    (Africa, Asia, Europe, North America, Oceania, South America)

    2. Create Dropdown 2 with All child categories (countries) of the category “North America”.
    Go to “Advanced Tab” and set conditional formatting to
    “Show” if “All”
    “Continent” is “North America”

    3. Create Dropdown 3 with all child categories (states) of Category “United States”
    Go to “Advanced Tab” and set conditional formatting to
    “Show” if “All”
    “United States” is “New York”

    4. Final Dropdown has New York Counties. Select “Broome County”

    My roadblock right now, is even with this structure, all posts created default to “Uncategorized” and not the final selected category. No Matter how I modify the Permalink structure.

    Any suggestions?
    WP 3.5.1
    GF 1.7.5
    Standard Categories, Standard Posts Types, Nothing custom.

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘Dynamic and Conditional Post Results’ is closed to new replies.