Skip to content

Instantly share code, notes, and snippets.

@r4nd1
Created August 13, 2017 14:45
Show Gist options
  • Save r4nd1/a8fcf012a7d5c00abd87121fa63da987 to your computer and use it in GitHub Desktop.
Save r4nd1/a8fcf012a7d5c00abd87121fa63da987 to your computer and use it in GitHub Desktop.
Custom Post Type Wordpress
// Add custom post type Tourists
function kdn_tourist_posttype() {
register_post_type( 'tourist',
array(
'labels' => array(
'name' => __( 'Tourists' ),
'singular_name' => __( 'Tourist' ),
'menu_name' => __( 'Tourists' ),
'name_admin_bar' => __( 'Tourist' ),
'parent_item_colon' => __( 'Parent Tourist:' ),
'all_items' => __( 'All Tourists' ),
'add_new' => __( 'Add New' ),
'add_new_item' => __( 'Add New Tourist' ),
'new_item' => __( 'New Tourist' ),
'edit_item' => __( 'Edit Tourist' ),
'update_item' => __( 'Update Tourist' ),
'view_item' => __( 'View Tourist' ),
'search_items' => __( 'Search Tourist' ),
'not_found' => __( 'No tourist found' ),
'not_found_in_trash' => __( 'No tourist found in trash' )
),
'hierarchical' => true,
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
// 'menu_position' => 4,
// 'menu_icon' => 'dashicons-analytics',
'show_in_admin_bar' => true,
'show_in_nav_menus' => true,
'can_export' => true,
'has_archive' => false,
'exclude_from_search' => false,
'publicly_queryable' => true,
'supports' => ['title', 'editor', 'author', 'thumbnail', 'revisions', 'custom-fields' ,'excerpt','comments','page-attributes'],
'capability_type' => 'post',
'rewrite' => ['slug' => 'tourist', 'with_front' => false], // Permalinks format
)
);
flush_rewrite_rules();
// register taxonomy
register_taxonomy('tourist_category', 'tourist', ['hierarchical' => true,
'labels' => array(
'name' => 'Categories',
'singular_name' => 'Tourist Category',
'search_items' => 'Search Tourist Categories',
'all_items' => 'All Tourist Categories',
'edit_item' => 'Edit Tourist Category',
'update_item' => 'Update Tourist Category',
'add_new_item' => 'Add New Tourist Category',
'new_item_name' => 'New Tourist Category',
'menu_name' => 'Categories'
),
'query_var' => true,
'show_admin_column' => true
]);
register_taxonomy('tourist_tags', 'tourist', ['hierarchical' => false,
'labels' => array(
'name' => __( 'Tags' ),
'singular_name' => __( 'Tags' ),
'search_items' => __( 'Search Tourist Tags' ),
'all_items' => __( 'All Tourist Tags' ),
'edit_item' => __( 'Edit Tourist Tags' ),
'update_item' => __( 'Update Tourist Tags' ),
'add_new_item' => __( 'Add New Tourist Tags' ),
'new_item_name' => __( 'New Tourist Tags'),
'menu_name' => __( 'Tags' )
),
'query_var' => true,
'show_admin_column' => true
]);
}
add_action( 'init', 'kdn_tourist_posttype');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment