WordPress.org

Ready to get started?Download WordPress

Forums

Custom rewrite rules aren't working (1 post)

  1. Rebecca Schaefer
    Member
    Posted 3 years ago #

    I had some custom code (which didn't work) then cycled through the Codex examples (which didn't work) and now I'm wondering what I'm doing wrong. The code I originally used worked properly on a different site, but it wasn't translating. In any case, here's what I have now.

    add_filter('rewrite_rules_array','wp_insertMyRewriteRules');
    add_filter('query_vars','wp_insertMyRewriteQueryVars');
    add_filter('init','flushRules');
    
    // Remember to flush_rules() when adding rules
    function flushRules(){
    	global $wp_rewrite;
       	$wp_rewrite->flush_rules();
    }
    
    // Adding a new rule
    function wp_insertMyRewriteRules($rules)
    {
    	$newrules = array();
    	$newrules['(project)/(\d*)$'] = 'index.php?pagename=$matches[1]&id=$matches[2]';
    	return $newrules + $rules;
    }
    
    // Adding the id var so that WP recognizes it
    function wp_insertMyRewriteQueryVars($vars)
    {
        array_push($vars, 'id');
        return $vars;
    }

    There is no "id" elemt in the wp_query array. I've reset my permalinks, logged in, logged out, refreshed, cleared cache, etc etc. Something's not right. So...Where am I going wrong?

Topic Closed

This topic has been closed to new replies.

About this Topic

  • RSS feed for this topic
  • Started 3 years ago by Rebecca Schaefer
  • This topic is not resolved
  • WordPress version: 3.0.1