WordPress REST API:如何发布到自定义帖子类型的自定义字段中?

时间:2019-09-24 11:18:42

标签: php wordpress custom-wordpress-pages wordpress-rest-api

我必须将一些数据发送到WordPress REST API来创建新的预订。 WordPress安装使用名为“ Soho Hotel Booking”的插件,负责管理WordPress方面的所有预订。

当我在GET API路由中镜像了POST响应以创建新的预订后,会创建一个新的预订,但是_booking_meta字段始终为空(我可以填写titleslug)。必须填写_booking_meta字段以创建正确且正确的预订。

我尝试使其与多种插件和方法一起使用:最有前途的是REST API Custom Fields,设置'show_in_rest' => true参数和register_rest_route函数。但是他们都不起作用。

有没有人有过通过WordPress API将数据发布到具有自定义字段的自定义帖子类型中的经验?

这是我发送给WordPress的正文,其中包括名为booking的自定义帖子类型,它表示一些名为_booking_meta的自定义字段:

{
  "id": 92089,
  "date": "2019-08-31T00:55:05",
  "date_gmt": "2019-08-30T22:55:05",
  "status": "publish",
  "type": "booking",
  "title": {
      "rendered": "[iCal][15.02.2020 – 22.02.2020]"
  },
  "meta": [],
  "_booking_meta": {
      "check_in": "2020-02-15",
      "check_out": "2020-02-22",
      "first_name": "",
      "payment_method": "",
      "amount_paid": "0.00",
      "ical_data": {
          "DTSTART": "20200215",
          "DTEND": "20200222",
          "SUMMARY": " CLOSED - Shane"
      },
      "booking_status": "2",
      "outstanding_amount": "0",
  },
  "_wp_page_template": ""
}

0 个答案:

没有答案