Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Register Custom Post Types
- function my_register_cpt() {
- $labels = array(
- 'name' => _x( 'symposium', 'Post Type General Name', 'gbc' ),
- 'singular_name'=> _x( 'Symposium', 'Post Type Singular Name', 'gbc' ),
- 'menu_name' => __( 'Symposiums', 'gbc' ),
- 'name_admin_bar => __( 'Symposiums', 'gbc' ),
- 'all_items' => __( 'All Symposiums', 'gbc' ),
- 'view_item' => __( 'View Symposium', 'gbc' ),
- 'add_new_item' => __( 'Add New Symposium', 'gbc' ),
- 'add_new' => __( 'Add New', 'gbc' ),
- 'edit_item' => __( 'Edit Symposium', 'gbc' ),
- 'update_item' => __( 'Update Symposium', 'gbc' ),
- 'search_items' => __( 'Search Symposium', 'gbc' ),
- 'not_found' => __( 'Not Found', 'gbc' ),
- 'not_found_in_trash' => __( 'Not found in Trash', 'gbc' ),
- );
- $args = array(
- 'label' => __( 'Symposium', '1fix' ),
- 'labels' => $labels,
- 'hierarchical' => true,
- 'public' => true,
- 'menu_icon' => 'dashicons-carrot',
- 'menu_position' => 5,
- 'supports' => array( 'title', 'editor','thumbnail', 'page-attributes' ),
- );
- register_post_type( 'symposium', $args );
- $labels = array(
- 'name' => _x( 'presentation', 'Post Type General Name', 'gbc' ), 'singular_name' => _x( 'Presentations', 'Post Type Singular Name', 'gbc' ),
- 'menu_name' => __( 'Presentations', 'gbc' ),
- 'name_admin_bar' => __( 'Presentations', 'gbc' ),
- 'all_items' => __( 'All Presentations', 'gbc' ),
- 'view_item' => __( 'View Presentation', 'gbc' ),
- 'add_new_item' => __( 'Add New Presentation', 'gbc' ),
- 'add_new' => __( 'Add New', 'gbc' ),
- 'edit_item' => __( 'Edit Presentation', 'gbc' ),
- 'update_item' => __( 'Update Presentation', 'gbc' ),
- 'search_items' => __( 'Search Presentation', 'gbc' ),
- 'not_found' => __( 'Not Found', 'gbc' ),
- 'not_found_in_trash' => __( 'Not found in Trash', 'gbc' ),);
- $args = array(
- 'label' => __( 'Presentations', 'gbc' ),
- 'labels' => $labels,
- 'hierarchical' => false,
- 'public' => true,
- 'rewrite' => array(
- 'slug' => 'presentation',
- 'with_front' => false,
- ),
- 'menu_icon' => 'dashicons-money',
- 'show_in_menu' => 'edit.php?post_type=symposium'
- );
- register_post_type( 'presentation', $args );
- $labels = array(
- 'name' => _x( 'speaker', 'Post Type General Name', 'gbc' ),
- 'singular_name' => _x( 'Speaker', 'Post Type Singular Name', 'gbc' ),
- 'menu_name' => __( 'Speakers', 'gbc' ),
- 'name_admin_bar' => __( 'Speakers', 'gbc' ),
- 'all_items' => __( 'All Speakers', 'gbc' ),
- 'view_item' => __( 'View Speaker', 'gbc' ),
- 'add_new_item' => __( 'Add New Speaker', 'gbc'),
- 'add_new' => __( 'Add New', 'gbc' ),
- 'edit_item' => __( 'Edit Speaker', 'gbc' ),
- 'update_item' => __( 'Update Speaker', 'gbc' ),
- 'search_items' => __( 'Search Speaker', 'gbc' ),
- 'not_found' => __( 'Not Found', 'gbc' ),
- 'not_found_in_trash' => __( 'Not found in Trash', 'gbc' ),
- );
- $args = array(
- 'label' => __( 'Speakers', 'gbc' ),
- 'labels' => $labels,
- 'hierarchical' => false,
- 'public' => true,
- 'rewrite' => array(
- 'slug' => 'speaker',
- 'with_front' => false,),
- 'menu_icon' => 'dashicons-groups',
- 'show_in_menu' => 'edit.php?post_type=symposium',
- 'show_in_rest' => true,
- 'supports' => array( 'title', 'editor','thumbnail','page-attributes' ));
- register_post_type( 'speaker', $args );
- $labels = array(
- 'name' => _x( 'session', 'Post Type General Name', 'gbc' ),
- 'singular_name' => _x( 'Session', 'Post Type Singular Name', 'gbc' ),
- 'menu_name' => __( 'Sessions', 'gbc' ),
- 'name_admin_bar' => __( 'Sessions', 'gbc' ));
- $args = array(
- 'label' => __( 'Sessions', 'gbc' ),
- 'labels' => $labels,
- 'hierarchical' => false,
- 'public' => true,
- 'menu_icon' => 'dashicons-media-video',
- 'show_in_menu' => 'edit.php?post_type=symposium'
- );
- register_post_type( 'session', $args );
- }
- add_action( 'init', 'my_register_cpt' );
- function my_add_rewrite_rules() {
- global $wp_rewrite;
- // Presentation rewrite
- add_rewrite_tag('%presentation%', '([^/]+)', 'presentation=');
- add_permastruct('presentation','/%symposium%/presentation/%presentation%', false);
- add_rewrite_rule('^presentation/([^/]+)/([^/]+)/?','index.php?presentation=$matches[2]','top');
- // Speaker rewrite
- add_rewrite_tag('%speaker%', '([^/]+)', 'speaker=');
- add_permastruct('speaker', '/%symposium%/speaker/%speaker%', false);
- add_rewrite_rule('^speaker/?([^/]+)/([^/]+)/?','index.php?speaker=$matches[2]','top');
- $wp_rewrite->flush_rules();
- }
- add_action( 'init', 'my_add_rewrite_rules' );
- function my_permalinks($permalink, $post, $leavename) {
- $post_id = $post->ID;
- if($post->post_type != 'speaker' && $post->post_type != 'presentation' && $post->post_type != 'session' || empty($permalink) || in_array($post->post_status, array('draft', 'pending', 'auto-draft'))){
- return $permalink;
- } else {
- $parent = $post->post_parent;
- $parent_post = get_post( $parent );
- $permalink = str_replace('%symposium%', $parent_post->post_name, $permalink);
- return $permalink;
- }
- }
- add_filter('post_type_link', 'my_permalinks', 10, 3);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement