Call a function in add_rewrite_rule?

I have a specific URL-function that returns proper pretty URLs for my own plugin that I want to use for 301-redirecting.

So what I need to do is take

Read More

/groups/123_ABC

and pass

123

into my function

getPrettyURL(123)

So I thought I could do:

add_rewrite_rule('^/groups/(?:.+/)?(d+)/?$', getPrettyURL($matches[1]), 'top');

but that does not work. What’s wrong?

Related posts

Leave a Reply

1 comment

  1. Looking at the Rewrite API provided by WordPress; I see that you don’t want the leading / in your regex.

    Try

    add_rewrite_rule('^groups/(d+)[_a-zA-Z]+/?$', getPrettyURL($matches[1]), 'top');