I am trying to add custom rules using wordpress's add_rewrite_rule function, but they don't work. The weird thing is that the rules are added and match my URL whenever I inspect them with the Monkeyman Rewrite Analyzer plugin.
When I try to access the page, it redirects to an incorrect location.
Here is my code:
add_rewrite_tag('%cc%','([a-zA-Z]+)');
add_rewrite_tag('%id%','([0-9]+)');
add_rewrite_rule('job-details/([0-9]+)$', 'index.php?pagename=jobs&cc=show&id=$matches[1]', 'top');
global $wp_rewrite;
$wp_rewrite->flush_rules();
As for my URLs, if I try to access the URL site.com/job-details/1 , it redirects me to /jobs/ , which is the page associated with my plugin.
Here is my .htaccess file
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
# uploaded files
RewriteRule ^files/(.+) wp-includes/ms-files.php?file=$1 [L]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule . index.php [L]
Turned out that my script was using a custom function to grab the GET parameters via the $_REQUEST object, which was being nullified by wordpress.
I used the following code to grab it instead.
global $wp_query;
$wp_query->query_vars['cc'];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With