WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

User selects category1 from wp_dropdown_categories, if user clicks on tag2 any point after, they only see posts from category1 with tag2, not all posts with tag2.

Is there a way to store the chosen category as a variable and use that to filter all content, until that variable is changed or removed?

share|improve this question
Can you provide a little context? What's your current code look like? – TheDeadMedic Nov 7 '12 at 23:29
Currently I just have the wp_dropdown_categories, really wasn't sure where to go with it from there, I just threw together a pastebin with pseudocode here, pastebin.com/CqiEXJZg – Chuck Nov 8 '12 at 14:14

Just use the selected argument:

wp_dropdown_categories( array(
    'show_option_all' => 'All Deployments',
    'hierarchical' => true,
    'show_count' => true,
    'selected' => get_query_var( 'cat' ),

Update: Hook onto the tag_link filter & add the current category (if applicable):

add_filter( 'tag_link', 'wpse_71874_tag_link_category_context' );

function wpse_71874_tag_link_category_context( $link ) {
    if ( is_category() && $cat_id = get_queried_object_id() )
        $link = add_query_arg( 'cat', $cat_id, $link );
    return $link;
share|improve this answer
Well that works as long as I only bounce from category to category, here's the catch. Say I have two posts, one is category1/tag1, the other is category2/tag1. If I'm looking at the post from category1 and click on it's tag (tag1) I only want to see category1/tag1 posts but instead I see all posts with tag1. – Chuck Nov 8 '12 at 14:40
Check my update. – TheDeadMedic Nov 8 '12 at 15:32

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.