I need to convert domain.com/agent/99/name to domain.com/agent/agentid=99 in wordpress. The site has a page name/slug “agent” (page_id=1882) and it must be pretty permalink enabled. My code works fine when pretty permalink disabled. But as soon as I enable pretty permalink (Post name) rewrite fails to work. I have tried both .htaccess and add_rewrite_rule.
Using .htaccess I tried this code below-
RewriteRule ^agent~([0-9]+)/(.+)$ agent/?agentid=$1 [NC,L]
Using add_rewrite_rule I tried this code below-
add_action( ‘init’, ‘rewriteAgentLink’);
add_rewrite_rule( “agent/([0-9]+)/(.+)/?$”, “index.php?page_id=1882&agentid=$matches”, “top”);
global $wp_rewrite; $wp_rewrite->flush_rules(true);
Please help! Thanks in advance.