如何使用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