Use Regular Expression to get tag from permalink url during wp_rewrite in generate_rewrite_rules

I’m messing with wp_rewrite and have spent the past few hours trying to figure regular expressions out again (i seem to have forgotten.) This is probably extremely easy for someone. Basically I’d like to match an alpha expression and stop at teh first occurance of a forward slash. Here’s what i’m doing:

I have a url

Read More

http://www.mydomain.com/basename/uniquename/page/2/

I want to get uniquename out with the following

'basename/(.*)/page/([0-9]{4})/?$' => 'index.php?post_type=basename&uniquenametaxonomy='.$wp_rewrite->preg_index(1).'&paged='.$wp_rewrite->preg_index(2),

obviously (.*) matches /page/ as well as uniquename and provides me with a query string looking like

?post_type=basname&uniquenametaxonomy=uniquename%2Fpage%2F2

I’d like it to be

?post_type=basname&uniquenametaxonomy=uniquename&paged=2

I know it has to be extremely easy, I’d like to match uniquename and stop at the first occurance of a forward slash.

Related posts

Leave a Reply

3 comments

  1. Wanted to update the answer letting you know that with all the extra wp_rewrites I was doing I needed to do

    ([a-z]*?) instead of (.*?) when I was parsing the url for words and @scribu’s answer (d+) when parsing numbers. But don’t forget that ?