• chaloum

    (@chaloum)


    Hi

    I having trouble adding permalinks. basically I am wanting the urls to be mysite.com/project/projectname

    where project is the page and projectname is the argument

    mysite.com/project?pn=The-project-name

    I seem to be able to get something of a permalink running but only it the argument is a number. for instance this works
    mysite.com/project/1 but I have a suspicion this works even without using permalinks

    but this doen’t
    mysite.com/project/projectname it just creates a page not found error

    I’ve looked at a number or solutions including the codex but nothing seems to work

    the code in my functions.php files is:

    add_filter( 'rewrite_rules_array','my_insert_rewrite_rules' );
    add_filter( 'query_vars','my_insert_query_vars' );
    add_action( 'wp_loaded','my_flush_rules' );
    
    function my_flush_rules(){
    	$rules = get_option( 'rewrite_rules' );
    
    		if ( ! isset( $rules['(projects)/[^/]+/([^/]+)/?$'] ) ) {
    		global $wp_rewrite;
    	   	$wp_rewrite->flush_rules();
    	}
    }
    
    function my_insert_rewrite_rules( $rules )
    {
    	$newrules = array();
    pagename=$matches[1]&id=$matches[2]';
    $newrules['(projects)/[^/]+/([^/]+)/?$'] = 'index.php?pagename=$matches[1]&pn=$matches[2]';
    
    	return $newrules + $rules;
    }
    
    function my_insert_query_vars( $vars )
    {
        array_push($vars, 'id');
        return $vars;
    }

    anyone able to help me out with this?

    thanks

  • The topic ‘Adding Permalinks’ is closed to new replies.