如何使用WP REST API(v1或v2)從特定自定義帖子類型獲取所有帖子?我對此很陌生,並試圖瞭解如何做到這一點。來自帖子類型的WP REST API提取帖子
我目前使用WP REST API v2和管理這個
http://domain.com/wp-json/wp/v2/types
獲取所有的職位類型的列表,然後設法得到這個職位類型我感興趣的是與
http://domain.com/wp-json/wp/v2/types/the-icons-update
如何從特定內容類型獲取所有帖子?
我試圖與
http://domain.com/wp-json/wp/v2/posts?filter[post_type]=the-icons-update
但它返回一個空數組(我想它返回默認的職位和我的網站上有自定義類型後只有內部的職位我試圖找回)。
難道我註冊的帖子類型有問題嗎?
function custom_post_type() {
$labels = array(
'name' => _x('The Icons Update', 'post type general name'),
'singular_name' => _x('The Icons Update', 'post type singular name'),
'add_new' => _x('Add Page', 'magazine'),
'add_new_item' => __('Add New Page'),
'edit_item' => __('Edit Page'),
'new_item' => __('New Page'),
'all_items' => __('All Pages'),
'view_item' => __('View Page'),
'search_items' => __('Search Pages'),
'not_found' => __('No Page found'),
'not_found_in_trash' => __('No Page found in the Trash'),
'parent_item_colon' => '',
'menu_icon' => '',
'menu_name' => 'The Icons Update'
);
$args = array(
'labels' => $labels,
'description' => 'Holds our projects and project specific data',
'public' => true,
'menu_position' => 5,
'supports' => array('title', 'editor', 'thumbnail', 'excerpt', 'custom-fields'),
'has_archive' => true,
'taxonomies' => array('post_tag', 'category'),
'hierarchical' => false,
'query_var' => true,
'queryable' => true,
'searchable' => true,
'rewrite' => array('slug' => 'the-icons-update')
);
register_post_type('magazine', $args);
flush_rewrite_rules();
}
add_action('init', 'custom_post_type');
任何幫助,這是非常感謝。
我在哪裏添加?謝謝。 – Si8
@Si8在你的'functions.php'文件中;) –
我只想包含帖子的ID,這就是全部。上述工作?如果有必要,我可以提出一個新問題。謝謝 – Si8