Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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!

share|improve this question
1  
It's a missing '$' before matches[1]. I'll post the answer as soon as my reputation allows me. –  Eric Harrison Jul 26 '12 at 16:58
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.