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?

  • 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;
  • 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 clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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