Advertisement
Guest User

Untitled

a guest
May 25th, 2019
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.11 KB | None | 0 0
  1. function codex_custom_init() {
  2. $args = array(
  3. 'public' => true,
  4. 'label' => 'What we do',
  5. 'has_archive' => 'what-we-do',
  6. 'query_var' => true,
  7. 'rewrite' => array('slug' => 'what-we-do/%wwd-category%'),
  8. 'taxonomies' => array( 'wwd-category' ),
  9. 'supports' => array( 'title', 'editor', 'thumbnail', 'revisions' )
  10. );
  11. register_post_type( 'what-we-do', $args );
  12.  
  13. register_taxonomy(
  14. 'wwd-category',
  15. 'what-we-do',
  16. array(
  17. 'label' => __( 'Categories WWD' ),
  18. 'hierarchical' => true,
  19. 'query_var' => true,
  20. 'rewrite' => array( 'slug' => 'what-we-do', 'with-front' => false)
  21. )
  22. );
  23. }
  24.  
  25. add_action( 'init', 'codex_custom_init' ,1);
  26.  
  27. function tm_wwd_category_post_link( $post_link, $id = 0 ){
  28. $post = get_post($id);
  29. $terms = wp_get_object_terms( $post->ID, 'wwd-category' );
  30. if( $terms ){
  31. return str_replace( '%wwd-category%' , $terms[0]->slug , $post_link );
  32. } else {
  33. return str_replace( '%wwd-category%/' , '' , $post_link );
  34. }
  35.  
  36. return $post_link;
  37. }
  38. add_filter( 'post_type_link', 'tm_wwd_category_post_link', 1, 3 );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement