Advertisement
Guest User

Untitled

a guest
Nov 26th, 2014
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.02 KB | None | 0 0
  1. function cpt_init() {
  2.  
  3. $labels = array(
  4. 'name' => 'Landen'
  5. );
  6.  
  7. $args = array(
  8. 'labels' => $labels,
  9. 'public' => true,
  10. 'publicly_queryable' => true,
  11. 'show_ui' => true,
  12. 'show_in_menu' => true,
  13. 'query_var' => true,
  14. 'rewrite' => array(
  15. 'slug' => 'landen',
  16. 'with_front' => FALSE,
  17. ),
  18. 'with_front' => false,
  19. 'capability_type' => 'post',
  20. 'has_archive' => true,
  21. 'hierarchical' => true,
  22. 'menu_position' => null,
  23. 'supports' => array( 'title', 'editor' )
  24. );
  25.  
  26. register_post_type('landen',$args);
  27.  
  28. $labels = array(
  29. 'name' => 'Rondreizen'
  30. );
  31.  
  32. $args = array(
  33. 'labels' => $labels,
  34. 'public' => true,
  35. 'publicly_queryable' => true,
  36. 'show_ui' => true,
  37. 'show_in_menu' => true,
  38. 'query_var' => true,
  39. 'rewrite' => array(
  40. 'slug' => 'landen/%landen%',
  41. 'with_front' => FALSE,
  42. ),
  43. 'with_front' => false,
  44. 'capability_type' => 'post',
  45. 'has_archive' => true,
  46. 'hierarchical' => true,
  47. 'menu_position' => null,
  48. 'supports' => array( 'title', 'editor', 'page-attributes')
  49. );
  50.  
  51. register_post_type('rondreizen',$args);
  52.  
  53.  
  54. }
  55.  
  56. add_action( 'init', 'cpt_init' );
  57.  
  58. add_action( 'init', 'my_website_add_rewrite_tag' );
  59. function my_website_add_rewrite_tag() {
  60.  
  61. add_rewrite_rule( '^landen/([^/]*)/([^/]*)/?','index.php?rondreizen=$matches[2]','top' );
  62. }
  63.  
  64.  
  65. add_filter( 'post_type_link', 'my_website_filter_post_type_link', 1, 4 );
  66. function my_website_filter_post_type_link( $post_link, $post, $leavename, $sample ) {
  67. switch( $post->post_type ) {
  68.  
  69. case 'rondreizen':
  70.  
  71.  
  72. if ( $landen = array_shift( wp_get_object_terms( $post->ID, 'landen' ) ) ) {
  73. if ( isset( $landen->slug ) ) {
  74. // create the new permalink
  75. $post_link = home_url( user_trailingslashit( 'landen/' . $landen->slug . '/rondreizen/' . $post->post_name ) );
  76. }
  77. var_dump($landen);
  78.  
  79. }
  80.  
  81. break;
  82.  
  83. break;
  84.  
  85. }
  86. return $post_link;
  87. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement