The code I’m using to rewrite urls with query vars:
function add_query_vars($aVars) {
$aVars[] = "city";
$aVars[] = "address";
$aVars[] = "pg";
return $aVars;
}
// hook add_query_vars function into query_vars
add_filter('query_vars', 'add_query_vars');
function add_rewrite_rules($aRules) {
$aNewRules = array( 'listing/([a-zA-Z-0-9]+)/([a-zA-Z-0-9]+)$' => 'index.phppagename=listing&city=$matches[1]&address=$matches[2]',
'([a-zA-Z-_]+)/pg/([0-9]+)$' => 'index.php?pagename=matches[1]&pg=$matches[2]');
$aRules = $aNewRules + $aRules;
return $aRules;
}
// hook add_rewrite_rules function into rewrite_rules_array
add_filter('rewrite_rules_array', 'add_rewrite_rules');
listing/Tokyo/89465-this-is-address
seems to work fine,
but I get a 404
error as soon as I put wordpress-page/pg/3
in the url
I’m using the standard “pretty permalinks” option in wp settings.
Can the wp query var: “pagename
” be variable? Or is there something else wrong with my code?
Thanks in advance!