So I have a WordPress page here:
http://12.ourgreenville.com/real_estate/
I want to be able to place two variable (city/state) in the URL, then work
with them. A URL would look like this:
http://12.ourgreenville.com/real_estate/1/2/
Please let me know what is needed. I placed your code in functions.php as
follows:
function add_rewrite_rules( $wp_rewrite )
{
$new_rules = array(
'('.$template_page_name.')/real_estate/(.*?)/?([0-9]{1,})/?$' =>'index.php?p=5351city='.$wp_rewrite->preg_index(1).'&state='.$wp_rewrite->preg_index(2)
);
$wp_rewrite->rules = $new_rules + $wp_rewrite->rules;
}
add_action('generate_rewrite_rules', 'add_rewrite_rules');
function query_vars($public_query_vars) {
$public_query_vars[] = "city";
$public_query_vars[] = "state";
return $public_query_vars;
}
add_filter('query_vars', 'query_vars');
I don’t know what i am doing wrong.kindly help me.
There is one very important step you missed – to flush the rules in order to activate your changes on them. Here it is my working variant with adaption for your case:
Prefix, in case of procedural implementation as yours is very important. You can place anything you like, but it allows you to escape situations of duplicated common names.
It is not exactly necessary to use the selected actions or filters you should be able to use yours, but important is to make your rule with higher priority (top) and to flush the rules.
prefix_attach_page_rules
will tell WordPress for our rulesprefix_attach_page_request
will do our job when parsing_request in this case by the given query vars.There is another StackOverflow: WordPress Answers – dedicated on WordPress, you could find many solutions there, also.
Additional (for the regex based on the comment link):
Then you should search them
real_estate_city_id
andreal_estate_state_id
in query vars and page_request…