• Seans0n

    (@seans0n)


    I’m attempting to have my WordPress plugin create its own permalinks and after reading through this guide (https://codex.www.ads-software.com/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?

Viewing 1 replies (of 1 total)
  • Thread Starter Seans0n

    (@seans0n)

    Does anyone have any experience or know of any plugins which create permalinks? I tried an e-commerce plugin but I couldn’t find in the code where the permalinks were set.

Viewing 1 replies (of 1 total)
  • The topic ‘Permalinks, permalinks!’ is closed to new replies.