Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function codex_custom_init() {
- $args = array(
- 'public' => true,
- 'label' => 'What we do',
- 'has_archive' => 'what-we-do',
- 'query_var' => true,
- 'rewrite' => array('slug' => 'what-we-do/%wwd-category%'),
- 'taxonomies' => array( 'wwd-category' ),
- 'supports' => array( 'title', 'editor', 'thumbnail', 'revisions' )
- );
- register_post_type( 'what-we-do', $args );
- register_taxonomy(
- 'wwd-category',
- 'what-we-do',
- array(
- 'label' => __( 'Categories WWD' ),
- 'hierarchical' => true,
- 'query_var' => true,
- 'rewrite' => array( 'slug' => 'what-we-do', 'with-front' => false)
- )
- );
- }
- add_action( 'init', 'codex_custom_init' ,1);
- function tm_wwd_category_post_link( $post_link, $id = 0 ){
- $post = get_post($id);
- $terms = wp_get_object_terms( $post->ID, 'wwd-category' );
- if( $terms ){
- return str_replace( '%wwd-category%' , $terms[0]->slug , $post_link );
- } else {
- return str_replace( '%wwd-category%/' , '' , $post_link );
- }
- return $post_link;
- }
- add_filter( 'post_type_link', 'tm_wwd_category_post_link', 1, 3 );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement