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 have been reading around and cannot seem to figure this out.

Everything is working fine except that pagination seems to not work, I am adding a second rewrite rule, shouldn't this fix that?

I can get to the first page fine, but any page beyond throws a 404.

Here is my code:

// Rewrite the Sermon URL
function sermon_rewrite() {
    $cpt = 'sermon';
    $tax = 'series';

    add_rewrite_rule(
        '^'.$cpt.'/([^/]+)/([^/]+)/([^/]+)/?',
        'index.php?post_type='.$cpt.'&'.$tax.'=$matches[1]&'.$tax.'=$matches[2]&'.$cpt.'=$matches[3]',
        'top'
    );
    add_rewrite_rule(
        'sermon/([^/]+)/page/?([0-9]{1,})/?$',
        'index.php?post_type='.$cpt.'&'.$tax.'=$matches[1]&paged=$matches[2]',
        'top'
    );
}
add_action('init','sermon_rewrite');

EDIT

If I go to the following url

This works: mysite.com/sermon/term/childterm/page2/

This does not: mysite.com/sermon/term/childterm/page2/

Any idea what is causing that?

share|improve this question
add comment

2 Answers

This works: mysite.com/sermon/term/childterm/page2/

This does not: mysite.com/sermon/term/childterm/page2/


according to your rewrite rule, I guess what you mean is

This works: mysite.com/sermon/term/page2/

This does not: mysite.com/sermon/term/childterm/page2/

I'm not a regex expert so I only come up with adding another rewrite rule to handle the childterm situaion

add_rewrite_rule(
        'sermon/(.*?)/(.*?)/page/?([0-9]{1,})/?$',
        'index.php?post_type='.$cpt.'&'.$tax.'=$matches[2]&paged=$matches[3]',
        'top'
    );
share|improve this answer
add comment
up vote 0 down vote accepted

Figured it out. I had everything right, it just was not being called in the proper order. I should have been matching paged url's first before the post.

This is my working code:

// Rewrite the Sermon URL
function sermon_rewrite() {
    $cpt = 'sermon';
    $tax = 'series';

    add_rewrite_rule(
        '^'.$cpt.'/([^/]+)/page/([0-9]+)/?$',
        'index.php?post_type='.$cpt.'&'.$tax.'=$matches[1]&paged=$matches[2]',
        'top'
    );
    add_rewrite_rule(
        '^'.$cpt.'/([^/]+)/([^/]+)/([^/]+)/?',
        'index.php?post_type='.$cpt.'&'.$tax.'=$matches[1]&'.$tax.'=$matches[2]&'.$cpt.'=$matches[3]',
        'top'
    );
}
add_action('init','sermon_rewrite');
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.