Wordpress add_rewrite_rule is not working

2.1k Views Asked by At

I have used this code in my themes function.php file, to pass custom argument to a page in wordpress but it is not working. I am getting 404 page not found. What am I doing wrong?

function photo_details_vars() 
{
    add_rewrite_rule('^photo-details/([^/]*)/?','index.php?p=20&id=$matches[1]','top');
}
add_action('init', 'photo_details_vars');

I am new to wordpress. I found this idea from here - http://codex.wordpress.org/Rewrite_API/add_rewrite_rule please be nice and direct me to a solve.

Additionally how can I catch this url variables value from the template file of page no. 20

How should I use add_rewrite_tag() for this rewrite rule?

1

There are 1 best solutions below

0
On

Have you registered the query variable using add_rewrite_tag()? otherwise WordPress will not recognize the variable.

Additionally how can I catch this url variables value from the template file of page no. 20??

if I understand it correctly, are you asking about this: $_GET['p']?