I'm attempting to have my WordPress plugin create its own permalinks and after reading through this guide (http://codex.wordpress.org/Custom_Queries#Custom_Archives) I copied and pasted the code almost tit for tat:
// Permalinks
function geotag_queryvars( $qvars ){
$qvars[] = 'geostate';
return $qvars;
}
global $wp_query;
if( isset( $wp_query->query_vars['geostate'] )) {
echo 'Permalinks seem to be working!';
}
function geotags_flush_rewrite_rules() {
global $wp_rewrite;
$wp_rewrite->flush_rules();
}
function geotags_add_rewrite_rules( $wp_rewrite ) {
$new_rules = array(
'geostate/(.+)$' => 'index.php?geostate=' .
$wp_rewrite->preg_index(1) );
$wp_rewrite->rules = $new_rules + $wp_rewrite->rules;
}
add_action('generate_rewrite_rules', 'geotags_add_rewrite_rules');
add_action('init', 'geotags_flush_rewrite_rules');
add_filter('query_vars', 'geotag_queryvars' );
if(isset($_GET['geostate'])){
echo 'GET var is set.';
}
// End Permalinks
So what should happen is /geostate/test/ should be seen as the same as index.php?geostate=test and hence the if(isset($_GET['geostate'])){ part should echo 'GET var is set.'
Similarly the if( isset( $wp_query->query_vars['geostate'] )) { part should activate and echo 'Permalinks seem to be working!'.
When I browse to /geostate/test nothing happens and $_GET remains empty. I can't understand what I'm doing wrong or not doing, any ideas?