0
我創建了名爲「預訂」的自定義帖子類型。我想讓這個帖子類型只讀意味着「添加新的」和「編輯」選項不應該顯示在後端。 這篇文章類型不是與plugin.This相關的是簡單的自定義類型後,顯示預訂details.Here是我的代碼..如何在wordpress中只讀自定義文章類型?
function demotheme_register_post_types() {
//custom posttype booking
$booking_labels = array(
'name' => _x('Bookings', 'demotheme_booking', 'demotheme'),
'singular_name' => _x('Booking', 'demotheme_booking', 'demotheme'),
'menu_name' => _x('Bookings', 'demotheme_booking', 'demotheme'),
'name_admin_bar' => _x('Bookings', 'demotheme_booking', 'demotheme'),
'add_new' => _x('Add New', 'demotheme_booking', 'demotheme'),
'add_new_item' => __('Add New Booking', 'demotheme'),
'new_item' => __('New Booking', 'demotheme'),
'edit_item' => __('Edit Booking', 'demotheme'),
'view_item' => __('View Booking', 'demotheme'),
'all_items' => __('All Bookings', 'demotheme'),
'search_items' => __('Search Booking', 'demotheme'),
'parent_item_colon' => __('Parent Booking:', 'demotheme'),
'not_found' => __('No bookings found.', 'demotheme'),
'not_found_in_trash' => __('No bookings found in Trash.', 'demotheme'),
);
$booking_args = array(
'labels' => $booking_labels,
'public' => true,
'publicly_queryable' => true,
'show_ui' => true,
'show_in_menu' => true,
'query_var' => true,
'rewrite' => false,
'capability_type' => 'post',
'capabilities' => array('read_post'=>'read_demotheme_booking'),
'map_meta_cap' => true,
'has_archive' => true,
'hierarchical' => false,
'menu_position' => null,
'supports' => array('title', 'editor', 'excerpt', 'thumbnail', 'page-attributes')
);
register_post_type(DEMOTHEME_BOOKING_POST_TYPE, $booking_args);
//flush rewrite rules
flush_rewrite_rules();
}
//add action to create custom post type
add_action('init', 'demotheme_register_post_types');
在後端側,我想查看預訂/都只預訂選擇。不應顯示發佈或更新按鈕。
謝謝回答。但是我只想讓一個CPT只讀,而不是全部。 您建議的插件基於用戶角色。我認爲這些設置會影響所有帖子類型。插件爲不同功能提供功能。但這不適合我 – 2015-03-19 13:13:41
我仍然認爲這個插件是你正在尋找的,如果我正確地理解你。用戶管理員將始終能夠創建,發佈,編輯和刪除CPT,否則無法管理CPT,請更正?如果你想有一個只讀到特定的CPT,那麼你需要一個不同的用戶類型,例如說,「讀者」,和用戶角色編輯器內設置該用戶類型爲只讀到特定的CPT。通過將'map_meta_cap'設置爲true,您可以獲得基本功能。我不認爲你只能獲得閱讀能力;必須由用戶角色定義。 – 2015-03-19 14:36:47