Created
March 22, 2014 01:15
-
-
Save illucent/9699652 to your computer and use it in GitHub Desktop.
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
| function kv_recipe_permalinks( $permalink, $post ) { | |
| if ( $post->post_type !== 'recipes' ) | |
| return $permalink; | |
| $terms = get_the_terms( $post->ID, 'occasion' ); | |
| if ( ! $terms ) | |
| return str_replace( '%occasion%/', '', $permalink ); | |
| $post_terms = array(); | |
| foreach ( $terms as $term ) | |
| $post_terms[] = $term->slug; | |
| return str_replace( '%occasion%', implode( ',', $post_terms ) , $permalink ); | |
| } | |
| add_filter( 'term_link', 'kv_add_term_parents_to_permalinks', 10, 2 ); | |
| function kv_add_term_parents_to_permalinks( $permalink, $term ) { | |
| $term_parents = kv_get_term_parents( $term ); | |
| foreach ( $term_parents as $term_parent ) | |
| $permlink = str_replace( $term->slug, $term_parent->slug . ',' . $term->slug, $permalink ); | |
| return $permlink; | |
| } | |
| function kv_get_term_parents( $term, &$parents = array() ) { | |
| $parent = get_term( $term->parent, $term->taxonomy ); | |
| if ( is_wp_error( $parent ) ) | |
| return $parents; | |
| $parents[] = $parent; | |
| if ( $parent->parent ) | |
| kv_get_term_parents( $parent, $parents ); | |
| return $parents; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment