如何使用 WP REST API(v1 或 v2)从特定的自定义帖子类型中获取所有帖子?我对此很陌生,并试图了解如何做到这一点。
我目前正在使用 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' );
对此的任何帮助都非常感谢。