Created
October 1, 2015 19:37
-
-
Save fastmover/84c022182d9ce527746d to your computer and use it in GitHub Desktop.
This script will allow you to create output on all level's of slugs for a custom post type with a custom taxonomy.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| /* | |
| This script will allow you to create output on all level's of slugs for a custom post type with a custom taxonomy. | |
| Setup the Custom Post Type slug to be the base: | |
| /custom-post-type-slug/taxonomy-term/post-title | |
| For the below code, I'm using a custom post type registered as: recipe | |
| and a custom Taxonomy registered as: recipecategory | |
| make sure you use query_var => true in the setup of the CPT and Taxonomy | |
| for example: | |
| /recipe/chicken/chicken-potpie | |
| Navigation and templates: | |
| /recipes - archive-recipe.php | |
| /recipe/chicken - taxonomy.php | |
| /recipe/chicken/chicken-potpie - single-recipe.php | |
| */ | |
| function customTaxonomyRewrite() { | |
| add_rewrite_rule('(recipe)/(.+?)/(.+?)(/[0-9]+)?/?$','index.php?post_type=recipe&slug=$matches[1]&recipecategory=$matches[2]&recipe=$matches[3]&page=$matches[4]','top'); | |
| add_rewrite_rule('(recipe)/(.+?)/?/?$','index.php?recipecategory=$matches[2]','top'); | |
| add_rewrite_rule('^recipe/([^/]*)/?','index.php?recipecategory=$matches[1]','bottom'); | |
| add_rewrite_rule('^recipe/?$','index.php?post_type=recipe','bottom'); | |
| } | |
| add_action('init', 'customTaxonomyRewrite', 10, 0); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment