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 hope I can explain this properly:

I'm working on a project involving multiple post types and custom permalinks. I have a post type for TV/movie series/franchise and a separate post type for content (episodes, movies, Direct to video). For the content type, I currently have a permalink that is as so:

abc.com/watch/%content_series%/%content_type%/%postname%

Thank to the rewrite rules, the structure degrades: I can have archive paves that are just abc.com/watch/%content_series%/%content_type%/ or abc.com/watch/%content_series%/ no problem. The problem I run into is pagination. If I did abc.com/watch/one-piece/page/2, I hit a snag because instead of recognizing that I want page 2, it thinks page is a content_type and 2 is the name.

A screencap of rewrite Analyzer confirms this: enter image description here

So, the right rewrite is there, its just not taking precedence. Is there a way to make this work correctly?

EDIT: Here is the code that sets everything up:

//Query vars/tags   
    add_rewrite_tag('%content_series%','([^/]+)');
    add_rewrite_tag('%content_type%','([^/]+)');
    add_rewrite_tag('%content_num%','([0-9]{1,})');

    //Permastructs
    $content_struct = get_option('veda_content_slug') . '/%content_series%/%content_type%/%postname%';
    add_permastruct('veda_content', $content_struct, false);    
    add_rewrite_rule(  get_option('veda_content_slug') .'/?$', 'index.php?post_type=veda_content', 'top' ); 
share|improve this question
add comment

2 Answers

up vote 1 down vote accepted

I've shared this exact frustration before. The following should help return any lost sanity.

Your first rewrite is pretty loose and is not seeing your second rewrite because 'page' matches your second segment of ([^/]+). The way to fix this is reverse the order of registration within the code. If the paged rewrite is below the looser rule, place it one line above or vice/versa wherever you register the rewrite rules.

You'll see the rules appearing properly within the analyzer.

Hope this helps!

share|improve this answer
    
The page rewrite is built into WordPress, though. How would I make it work in that case? –  Manny Fleurmond Aug 17 '12 at 10:37
    
Did you add a content_type and content_series tags? Is this a rewrite rule? Can you post what you've done so I can get a better grasp on your situation. –  Brian Fegter Aug 17 '12 at 14:24
    
I added the code I am using in the main question. Thank you for any suggestions you have. –  Manny Fleurmond Aug 17 '12 at 23:47
add comment

Okay, after much experimenting, I found a solution. All I had to do was create some more custom rewrite rules to make it work:

//Custom rewrites
    add_rewrite_rule(
        $slug . '/page/([0-9]+)?/?$',
        'index.php?post_type=veda_content&paged=$matches[1]',
        'top'
    );
    add_rewrite_rule(
        $slug . '/([^/]+)/page/([0-9]+)?/?$',
        'index.php?post_type=veda_content&paged=$matches[2]&content_series=$matches[1]',
        'top'
    );
    add_rewrite_rule(
        $slug . '/([^/]+)/([^/]+)/page/([0-9]+)?/?$',
        'index.php?post_type=veda_content&paged=$matches[3]&content_series=$matches[1]&content_type=$matches[2]',
        'top'
    );

These do the trick in the rewrite analyzer. Hopes this helps someone else.

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.