Skip to content

Instantly share code, notes, and snippets.

@alimoshen
Created January 29, 2018 23:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alimoshen/3c7cb9aa1b41a7a94bb22768cca597fb to your computer and use it in GitHub Desktop.
Save alimoshen/3c7cb9aa1b41a7a94bb22768cca597fb to your computer and use it in GitHub Desktop.
Custom Rewrite rules
add_filter('rewrite_rules_array', 'mmp_rewrite_rules');
function mmp_rewrite_rules($rules) {
$newRules = array();
$newRules['expertise/(.+)/(.+)/(.+)/(.+)/(.+)/?$'] = 'index.php?expertise=$matches[5]'; // use the 5th tax segment
$newRules['expertise/(.+)/(.+)/(.+)/(.+)/?$'] = 'index.php?expertise=$matches[4]'; // use the 4th tax segment
$newRules['expertise/(.+)/(.+)/(.+)/?$'] = 'index.php?expertise=$matches[3]'; // use the 3rd tax segment
$newRules['expertise/(.+)/(.+)/?$'] = 'index.php?expertise=$matches[2]'; // use the 2nd tax segment
$newRules['expertise/(.+)/(.+)/?$'] = 'index.php?expertise_type=$matches[2]';
$newRules['expertise/(.+)/?$'] = 'index.php?expertise_type=$matches[1]';
return array_merge($newRules, $rules);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment