【问题标题】:Insert data into blog in WordPress by Json link通过 Json 链接将数据插入 WordPress 中的博客
【发布时间】:2019-05-12 05:33:18
【问题描述】:

我想通过 JSON 链接更新我的帖子,我已通过此链接获取所有帖子数据。 http://xyz/wp-json/custom/v1/all-posts。 如何设置 cron 作业以进行自动更新。

【问题讨论】:

  • 你想通过rest api插入帖子,不是吗?
  • 如果它工作正常,我会通过 api 来做这个
  • 如果您想迁移帖子,只需将所有内容导出并导入另一个网站。
  • 不,我想通过json代码插入

标签: mysql json database wordpress


【解决方案1】:
$slices = json_decode(file_get_contents('http://27.109.19.234/decoraidnew/wp-json/custom/v1/all-posts'),true); if ($slices) { foreach ($slices as $slice) {
  $title = $slice[1];
  } } $my_post = array(
 'post_title'    =>  $title,
 'post_content'  => 'This is my content',
 'post_status'   => 'publish',
 'post_author'   => 1,
 'post_category' => array(8,39) ); $post_id = wp_insert_post( $my_post, $wp_error );

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-01-24
    • 1970-01-01
    • 2013-05-15
    • 2014-08-28
    • 1970-01-01
    相关资源
    最近更新 更多