Created
February 13, 2019 21:21
-
-
Save moxdev/2150a0b0e23bcd30790f55ddd5fc693e to your computer and use it in GitHub Desktop.
Custom Taxonomy URL Rewrite Rule #wp
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
| add_action( 'init', 'custom_tax_rewrite_rule', 10, 0 ); | |
| /** | |
| * Rewrites the Property Location's url to be '/$slug/' | |
| * Example: | |
| * http://quantum.test/index.php?property_locations=virginia rewrites to | |
| * http://quantum.test/virginia/ | |
| * | |
| * @return void | |
| */ | |
| function custom_tax_rewrite_rule() { | |
| $cats = get_terms( | |
| 'property_locations', // edit this to be your custom taxonomy | |
| array( | |
| 'hide_empty' => false, | |
| ) | |
| ); | |
| if ( count( $cats ) ) { | |
| foreach ( $cats as $cat ) { | |
| add_rewrite_rule( $cat->slug . '/?$', 'index.php?property_locations=' . $cat->slug, 'top' ); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment