小编ejo*_*box的帖子

如何使用 WP REST API 从自定义帖子类型获取数据

我想使用 WP REST API 从自定义帖子类型获取数据。

我的自定义帖子类型是“结果”,我已尝试使用此参数。

http://ejobbox.com/wp-json/wp/v2/result/?

http://ejobbox.com/wp-json/wp/v2/result/?per_page=10
Run Code Online (Sandbox Code Playgroud)

并且还与

http://ejobbox.com/wp-json/wp/v2/posts/?post_type=result
Run Code Online (Sandbox Code Playgroud)

但我无法使用自定义帖子类型获取数据。

我还将其添加到我的自定义帖子类型中

'show_in_rest'=> true,
'rest_base'          => 'result',
'rest_controller_class' => 'WP_REST_Posts_Controller',
Run Code Online (Sandbox Code Playgroud)

我仍然没有得到任何结果。

请问,您能告诉我我在这里做错了什么吗?我该怎么做才能从自定义帖子类型中获取数据?请给我一个建议。

我的 Function.php (自定义帖子类型)代码在这里:

function codexres_custom_init() {
    $args = array(
      'public' => true,
      'label'  => 'Result'
    );
    register_post_type( 'result', $args );
}
add_action( 'init', 'codexres_custom_init' );


function codex_result_init() {
    $labels = array(
        'name'               => _x( 'Result', 'post type general name', 'your-plugin-textdomain' ),
        'singular_name'      => _x( 'Result', 'post type singular name', 'your-plugin-textdomain' ),
        'menu_name'          => _x( 'Result', 'admin …
Run Code Online (Sandbox Code Playgroud)

rest wordpress

7
推荐指数
3
解决办法
4万
查看次数

标签 统计

rest ×1

wordpress ×1