douzi7219 2016-08-17 10:05
浏览 79
已采纳

如何通过REST-API在WordPress中获取插件的自定义帖子?

I am now creating an android app which planned to connect to a plugin(WP Job Manager) in my WordPress side. I installed REST-API plugin and successfully getting posts by:

mywp.org/wp-json/wp/v2/posts

However, results do not include custom posts which created by the plugin. I am new in rest-api and I am not sure what I should do.

Thankyou!

  • 写回答

1条回答 默认 最新

  • dtio35880438 2016-08-17 17:36
    关注

    There are solutions, but the basic idea is that the custom post type must be registered with WP REST API.

    You can refer to this link: http://v2.wp-api.org/extending/custom-content-types/

    It should be something like this (put it in your functions.php, "cpt" = Custom Post Type, an arbitrary name):

    function wpsd_add_cpt_args() {
        global $wp_post_types;
    
        $wp_post_types['cpt']->show_in_rest = true;
        $wp_post_types['cpt']->rest_base = 'cpt';
        $wp_post_types['cpt']->rest_controller_class = 'WP_REST_Posts_Controller';
    }
    add_action( 'init', 'wpsd_add_cpt_args', 30 );
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 ansys fluent计算闪退
  • ¥15 有关wireshark抓包的问题
  • ¥15 需要写计算过程,不要写代码,求解答,数据都在图上
  • ¥15 向数据表用newid方式插入GUID问题
  • ¥15 multisim电路设计
  • ¥20 用keil,写代码解决两个问题,用库函数
  • ¥50 ID中开关量采样信号通道、以及程序流程的设计
  • ¥15 U-Mamba/nnunetv2固定随机数种子
  • ¥15 vba使用jmail发送邮件正文里面怎么加图片
  • ¥15 vb6.0如何向数据库中添加自动生成的字段数据。