[wp-hackers] Custom URL Rewrite Help

Md Mahmudur Rahman mahmudur at 79mplus.com
Tue Jul 2 09:17:13 UTC 2013


Dear Hackers,

I have a custom post type (artist), which has a custom URL rewrite for a
custom page template as given below:

*URL:* http://localhost/artist/artist-name/videos/3/

*Code for URL Rewrite:*

add_action( 'init', 'my_artist_rewrite_rule' );

function my_artist_rewrite_rule() {

            add_rewrite_rule( '([^/]+)/videos(/[0-9]+)?/?$',
'index.php?post_type=artist&name=$matches[1]&videos=yes&page=$matches[2]',
'top' );


        }

And I am manually flushing the permalink settings each time I am making any
change to the rewrite rule to reflect the changes. But it seems that the
custom rewrite rule is not working. Here is the response of the $wp object:

[query_vars] => Array
        (
            [name] => artist-name
            [page] => /3
            [news] => yes
            [post_type] => artist
        )

    [query_string] => name=artist-name&page=%2F3&news=yes&post_type=artist
    [request] => artist/artist-name/3
    [matched_rule] => ([^/]+)(/[0-9]+)?/?$
    [matched_query] => name=artist-name&page=%2F3
    [did_permalink] => 1

So the requesting URL is always matching to the below rule ignoring the
custom rewrite rule:

    [matched_rule] => ([^/]+)(/[0-9]+)?/?$

I have checked the custom rule with a rewrite rules inspector plugin and
requested URL always matched with the custom URL rewrite rule but that is
not the case in real.

Not sure what is happening behind? Hope someone can give me a clue.

*Many thanks,*

*Mahmudur Rahman*

<http://www.79mplus.com/>


More information about the wp-hackers mailing list