Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I figured out I can filter posts by format just by doing /type/{format} e.g. /type/gallery/ in the url.

Looking for a way to filter by categories on top of this, something like /type/gallery/category/installation or /type/gallery/art.

I've figured out the query, but I don't know how to handle the url bit:

$galleryquery = wp_parse_args($query_string);
$galleryquery['tax_query'] = array(
    array(
        'taxonomy' => 'post_format',
        'terms' => array('post-format-gallery'),
        'field' => 'slug',
    ),
    array(
        'taxonomy' => 'category',
        'terms' => array('installation'),
        'field' => 'slug',
    ),
);
query_posts($galleryquery);

Ideas? I'm guessing I have to intercept the permalink and somehow pass it to my query...

Site is reachable here

share|improve this question
    
Ok, filtering out post formats did work out for you like this: /type/{post_format}. Now let's try to do this: /type/{post_format}/?category=installation. Does it work? –  kaiser Mar 19 '13 at 7:10
    
No, that doesn't seem to do anything. –  two7s_clash Mar 20 '13 at 15:37
    
Ehm... did you uncomment/remove your code before you tried that? Have you deactivated all plugin? Switched back to Twenty Ten? –  kaiser Mar 20 '13 at 15:42
    
    
No, you haven't. There's a permanent redirect to wp-login.php... –  kaiser Mar 21 '13 at 1:56
show 1 more comment

3 Answers 3

I am doing something similar, but for member pages. I was able to use the code in my answer linked here which parses the information in the URL which can be manipulated within WordPress.

http://wordpress.stackexchange.com/a/91399/12920

Here's a snippet of the URL handling portion which perhaps will get you started? Granted you're doing something different than me, but the underlying function should be very similar.

// Catch the URL and redirect it to a template file
function userpage_rewrite_catch() {
    global $wp_query;

    if ( array_key_exists( 'member', $wp_query->query_vars ) ) {
        // Do something if member is in the URL
        include (TEMPLATEPATH . '/user-profile.php');
        exit;
    }
}
add_action( 'template_redirect', 'userpage_rewrite_catch' );
share|improve this answer
add comment

A possible approach is to create a new rewrite rule to handle the custom url. I haven't tested the code, but it goes something like this:

function add_category_query_var($query_vars) {
    array_push($query_vars, 'post_type');
    array_push($query_vars, 'post_category');
    return $query_vars;
}

add_filter('query_vars','add_category_query_var');

/* create new rewrite rule*/
function add_category_rewrite_rule($wp_rewrite_rules) {

        $new_rewrite_rule['type/([^/]+)/category/([^/]+)/?$'] = 'index.php?post_type=$matches[1]&post_category=$matches[2]';

        $wp_rewrite_rules = $new_rewrite_rule + $wp_rewrite_rules;

        return $wp_rewrite_rules;
}

add_filter('rewrite_rules_array', 'add_category_rewrite_rule');

Then you would access the new variable like so:

$galleryquery['tax_query'] = array(
    array(
        'taxonomy' => 'post_format',
        'terms' => array('post-format-gallery'),
        'field' => 'slug',
    ),
    array(
        'taxonomy' => 'category',
        'terms' => array($_GET['post_category']),
        'field' => 'slug',
    ),
);
share|improve this answer
    
yes, I think I would want to go this route. However, when I try to enter dev.thegarage-cville.com/… it redirects to dev.thegarage-cville.com/… and just loads the blog index. I take it I need to get the Public query vars working first. Thoughts? –  two7s_clash Mar 26 '13 at 17:55
    
Save the WordPress permalinks first to trigger the activation of the new rewrite rule. Also confirm that it's indeed picking the new variables. –  KalenGi Mar 26 '13 at 18:03
    
Your answer was helpful, thanks, although adding the variables was unneeded for what I asked. –  two7s_clash Mar 27 '13 at 20:12
add comment
up vote 0 down vote accepted

I ended up with this:

function when_rewrite_rules( $wp_rewrite ) {
  $newrules = array();
  $new_rules['type/([^/]+)/category/([^/]+)/?$'] = 'index.php?post_format=$matches[1]&category_name=$matches[2]';
  $wp_rewrite->rules = $new_rules + $wp_rewrite->rules;
}
add_filter('generate_rewrite_rules','when_rewrite_rules');

There is no need to add new query vars. You can get both taxonomies out of the box: categories are query-able with "?category_name=x" and post formats with "?post_format=x".

Confusingly, post formats are a taxonomy, and not a custom post type, yet have the taxonomy of "type". E.g. you filter them like so:

mysite.com/type/gallery

Seems like "/format/" would be a better taxonomy to avoid confusion with Custom Post Type.

share|improve this answer
add comment

Your Answer

 
discard

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.