Using permalink url to pass parameters
-
I am writing a custom plugin, and I need to have a URL such as:
https://www.domain.com/locations/123-denver/
which translates to the ugly URL which works great:
https://www.domain.com/locations/?nw_id=123
Notice the 123 value. Everything after that number can be ignored, and is only there for SEO purposes (have the city in the URL is good for SEO but all my program needs is the nw_id number to pull the correct profile).
The two parameters that I need to pass are:
1. The page_id so it pulls up the correct page which contains the shortcode which calls the plugin.
2. The nw_id, which tells my plugin which profile or “location info” to load up.
Here’s the wp_rewrite rule I’m using:
function nw_add_rewrite_rule() {
add_rewrite_rule(
'^locations/([0-9]+)',
'index.php?nw_id=$1&page_id=19',
'top'
);
}
add_action('init','nw_add_rewrite_rule');I can get it to pull up the correct page (page_id value is being passed correctly) but it won’t load up the specific profile (because nw_id is not being passed).
- The topic ‘Using permalink url to pass parameters’ is closed to new replies.