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 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化