據我瞭解,WordPress的有5種大文章類型:(郵局,頁面,附件,修訂和nav_menu_item)
爲了查找的「事件」,你需要一個post_type已經註冊了這個自定義後鍵入使用register_post_type
函數。
這裏是你如何可以創建一個自定義後類型,稱爲「事件」的樣本
add_action('init', 'create_post_type');
function create_post_type() {
register_post_type('event',
array(
'labels' => array('name' => __('events'),
'singular_name' => __('event')),
'public' => true,
)
);
}
注:register_post_type($post_type, $args)
默認情況下需要兩個參數。
$post_type
- 是你的自定義文章類型的名稱。
$args
- 是任何數量的參數修改後類型的默認行爲。這通常應該是一個數組。
的'labels'
參數描述了一般單數形式的崗位類型的名稱。如果您喜歡使用一般和單式的帖子類型,請使用顯示的方法。否則,默認值就是您提供的$post_type name
名稱。如果柱式旨在供公衆使用
'public'
論點說。
你也可以寫一個簡化版沒有太多的標籤,如:
add_action('init', 'create_post_type');
function create_post_type() {
register_post_type('event', array('public' => true, 'label' => 'events'));
}
還要注意的是create_post_type
是,你可以打電話my_super_cool_new_custom_original_post_type_creating_function
哈哈或描述性的東西爲自己需要的功能自定義名稱。
在簡化版本中,我使用了label
,它採用一個參數,這是帖子類型的一般名稱。如果你想補充說明您的文章類型,你會在括號中的名字中做到這一點,更換一個下劃線爲X,如:謹慎
add_action('init', 'create_post_type');
register_post_type('event',
array(
'labels' => array('name' => _x('events' , 'post type general name'),
'singular_name' => _x('event' , 'post type singular name')),
'public' => true,
)
);
字:初始化之前不要使用register_post_type
。
現在,如果您已經完成了所有這些,並且無法訪問post_type,請確保已將公共參數添加到它。 :)
歡呼聲
出於好奇,你有一個名爲「事件」的註冊自定義帖子類型?你有沒有在你的數據庫post_type事件的任何條目? – maiorano84
你確定$ current_user_id = 5嗎?你確定你正在對同一個數據庫運行兩個查詢嗎? – Hobo
我有同樣的問題,您是否找到解決方案? – Pentium10