Last active
October 7, 2016 17:49
-
-
Save ccurtin/7aa7627e08a1d73b31ff to your computer and use it in GitHub Desktop.
Include taxonomy category in the slug: pretty-permalink. EX: www.website.com/portfolio/YOUR-CATEGORY/project-one
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 | |
| // In the $args variable: | |
| // For registering custom-post-type | |
| array('rewrite' => array('slug' => 'portfolio/%portfolio-media-type%','with_front' => false)); | |
| // For registering custom-post-type taxonomy | |
| array('rewrite' => array('slug' => 'portfolio' )); | |
| ?> | |
| <?php | |
| // Don't forget to update permalinks after implementing | |
| add_filter('post_link', 'portfolio_category', 1, 3); | |
| add_filter('post_type_link', 'portfolio_category', 1, 3); | |
| function portfolio_category($permalink, $post_id, $leavename) { | |
| //con %brand% catturo il rewrite del Custom Post Type | |
| if (strpos($permalink, '%portfolio-media-type%') === FALSE) return $permalink; | |
| // Get post | |
| $post = get_post($post_id); | |
| if (!$post) return $permalink; | |
| // Get taxonomy terms | |
| $terms = wp_get_object_terms($post->ID, 'portfolio-media-type'); | |
| if (!is_wp_error($terms) && !empty($terms) && is_object($terms[0])) | |
| $taxonomy_slug = $terms[0]->slug; | |
| else $taxonomy_slug = 'no-brand'; | |
| return str_replace('%portfolio-media-type%', $taxonomy_slug, $permalink); | |
| } | |
| ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment