Custom taxonomy Rewrite Rule

Question

I want my taxonomy url to be like this: site.com/page/taxonomy_term

How will I be able to achieve this? I have written a wordpress rewrite rule code in my functions.php like this:

function sphere_custom_rewrite_rules( $rules ){
    $newrules['(.+?)/([^/]*)/?'] = 'index.php?pagename=$matches[1]&positive_sphere=$matches[2]';
    $newrules['(.+?)/([^/]*)/?'] = 'index.php?pagename=$matches[1]&negative_sphere=$matches[2]';

    return $newrules + $rules;
}
add_filter('rewrite_rules_array', 'sphere_custom_rewrite_rules');

the page doesn’t return 404 error, but it doesn’t do my functions in taxonomy.php instead it’s doing my code on my template-page-name.php file. What I want is when I types this url:

site.com/page/taxonomy_term it’ll run my code on taxonomy.php.

Any help would be greatly appreciated! Thanks.

0
, Zais 8 months 0 Answers 101 views 0

Leave an answer