Its a WordPress Query and another add_rewrite_rule one for that matter.
What i want is to have a user enter the url and two custome marameters as such “foods/food“…. so the url is http://wordpress_home/foods/food.
Thing is that ‘foods’ is a redirect rule and i want to process ‘food’ further.
add_rewrite_rule( "^foods/([0-9]+)", "index.php?page_id=$matches[1]", "top" );
In the above example, the ‘foods’ bit works. i’m currently checking for numbers but I now want to use ‘food’ by sending it to another function, processing it by getting relevant data from the ‘food’ function and then using the returned data to complete the url. ‘Food’ might return the correct ‘page_id’ but a database call is necessary using ‘food’ to get the ‘page_id’ to complete the url so the correct page for the correct user(s) will display.
I can’t inject a function in to the rewrite rule above. Can any one help?
I’ve tried checkfood( $matches[1] )
but that just fails.
Thanks.
Add another parameter &foods=1 so you can identify in the template_redirect if it should do anything.
Note: If you are using hooks and actions, you won’t need to add a template handler as you can just ensure you pass along a URL parameter to identify when your code should run.
You can check the query_var for existence in your hooks and actions, and these query vars are not visible since they’re hidden by the rewrite.