• Hello!
    I am trying to recreate this page – http://www.aidforafrica.org/volunteer.php – in WordPress.

    I thought the best way to build it would be to use category dropdowns and list out the posts in the category selected, only if they’re also in the ‘volunteer-opportunities’ category, but it doesn’t seem to be working like that.

    I’d like to avoid having them choose the country category twice (once for the country archive and once for the volunteer opps). Does anyone have any thoughts on how I can achieve this?

Viewing 11 replies - 1 through 11 (of 11 total)
  • There is already a thread which discusses this in detail . Check this http://wordpress.org/support/topic/148005?replies=18

    Thread Starter phejster

    (@phejster)

    Yea, I found that one, but it uses query_posts and not form fields / category dropdowns.

    What I need is for the user to select a country from the category dropdown and displays posts that exist in that chosen category (country) and in the volunteer category.

    it uses query_posts and not form fields / category dropdowns

    Huh? Go read the page listed above properly. Then consider using get_post() to run a second loop for your dropdown selection.

    Thread Starter phejster

    (@phejster)

    Thank you Esmi!

    I was unfamiliar with the get_posts() function, and assumed it was deprecated function, replaced by query_posts. In case anyone else needs to do this, here is the code:

    <?php global $post; $myposts = get_posts('category=63'); ?>
    
    <form action="<?php bloginfo('url'); ?>/" method="get">
    <?php
    $select = wp_dropdown_categories('child_of=4&hide_empty=0&show_option_none=Select Country&echo=0');
    $select = preg_replace("#<select([^>]*)>#", "<select$1 onchange='return this.form.submit()'>", $select);
    echo $select; ?>
    <noscript><input type="submit" value="View" /></noscript>
    </form>
    Thread Starter phejster

    (@phejster)

    Ok, I’m not sure what happened. Maybe this never worked and it just seemed like it was but it’s not working now. I copied the above code exactly.

    Esmi (or anyone), am I using get_posts wrong? If I include the foreach then I get three category dropdowns.

    Can you help me understand what behavior you see and what you want. My assumption is you see:
    The dropdown is listing out all the countries, when selected taking you to the category page for that country with all posts listed.

    You want to see:
    A dropdown listing out all the countries, when selected it takes you to a filtered category page, only listing the volunteer-opportunities for the selected country

    Also to clarify – is 63 the volunteer-opportunities and 4 the parent category for all African countries?

    Thread Starter phejster

    (@phejster)

    webgdawg, exactly.

    When they use the drop down and select a country category, say Ethiopia, I want a filtered category archive of posts that are in the Ethiopia category AND the Volunteer Opp. category.

    You’re correct that 63 is the Volunteer Opp. cat and 4 is the Country parent.

    Thanks for the help, I’ve been pounding my head against the wall all day.

    Thread Starter phejster

    (@phejster)

    Does anyone know if this can be achieved?

    Thread Starter phejster

    (@phejster)

    My PHP developer and I are working on this using non-core code. Anyone know if this can be done with core-code?

    The default behavior for the drop down is to take you to the selected category, in your case the country page which is not what you want.

    You can do this leveraging the WordPress plugin hooks, the question which hooks are best…

    You could add hidden input field that stores the value of the volunteer-opp. category (63) passing that in the get url. You would check for this $_GET variable using the init hook (you want to catch it before WP turns it into a permalink), set a global variable with the value of the hidden field.

    No in your template file you can check for the global variable and modify the query using query_posts

    So basically you are using a hidden field in the form to capture the extra category to filter by, capturing it with the init hook and then using query_posts to modify the call to get the posts accordingly.

Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘Filter Categories Based on Another Category’ is closed to new replies.