Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function cpt_init() {
- $labels = array(
- 'name' => 'Landen'
- );
- $args = array(
- 'labels' => $labels,
- 'public' => true,
- 'publicly_queryable' => true,
- 'show_ui' => true,
- 'show_in_menu' => true,
- 'query_var' => true,
- 'rewrite' => array(
- 'slug' => 'landen',
- 'with_front' => FALSE,
- ),
- 'with_front' => false,
- 'capability_type' => 'post',
- 'has_archive' => true,
- 'hierarchical' => true,
- 'menu_position' => null,
- 'supports' => array( 'title', 'editor' )
- );
- register_post_type('landen',$args);
- $labels = array(
- 'name' => 'Rondreizen'
- );
- $args = array(
- 'labels' => $labels,
- 'public' => true,
- 'publicly_queryable' => true,
- 'show_ui' => true,
- 'show_in_menu' => true,
- 'query_var' => true,
- 'rewrite' => array(
- 'slug' => 'landen/%landen%',
- 'with_front' => FALSE,
- ),
- 'with_front' => false,
- 'capability_type' => 'post',
- 'has_archive' => true,
- 'hierarchical' => true,
- 'menu_position' => null,
- 'supports' => array( 'title', 'editor', 'page-attributes')
- );
- register_post_type('rondreizen',$args);
- }
- add_action( 'init', 'cpt_init' );
- add_action( 'init', 'my_website_add_rewrite_tag' );
- function my_website_add_rewrite_tag() {
- add_rewrite_rule( '^landen/([^/]*)/([^/]*)/?','index.php?rondreizen=$matches[2]','top' );
- }
- add_filter( 'post_type_link', 'my_website_filter_post_type_link', 1, 4 );
- function my_website_filter_post_type_link( $post_link, $post, $leavename, $sample ) {
- switch( $post->post_type ) {
- case 'rondreizen':
- if ( $landen = array_shift( wp_get_object_terms( $post->ID, 'landen' ) ) ) {
- if ( isset( $landen->slug ) ) {
- // create the new permalink
- $post_link = home_url( user_trailingslashit( 'landen/' . $landen->slug . '/rondreizen/' . $post->post_name ) );
- }
- var_dump($landen);
- }
- break;
- break;
- }
- return $post_link;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement