如何通过所有CUSTOM FIELDS的REST API创建自定义帖子类型? WORDPRESS WP-API

时间:2017-12-08 07:42:27

标签: php json wordpress rest api

我试图创建自定义的post-type" property"来自REST Api。我能够成功创建它,我只是传递了标题和内容。但我还想将值插入元,如CITY,Price,Type,Status Country。这些是HOUZEZ主题的一部分。如何使用所有这些值创建此类型的PROPERTY?请建议。

截至目前,这是我的代码。请建议添加什么。

<?php
///////////////////////////////////////////////////////////////////////////////////
//                                                                               //
// This is using a sample local WordPress Install and is not production safe     //
// It uses the  REST and Basic Auth plugins                                      //
//                                                                               //
///////////////////////////////////////////////////////////////////////////////////
// setup user name and password
$username = '*****';
$password = '*****';
// the standard end point for posts in an initialised Curl
$process = curl_init('http://205.147.97.184/unified/index.php/wp-json/wp/v2/property');
// create an array of data to use, this is basic - see other examples for more complex inserts
$data = array('slug' => 'rest_insert2' , 'title' => 'REST API insert22w' , 'content' => 'The content of our stuff', 'excerpt' => 'smaller', 'status' => 'publish' , 'property_city-all' => 'in-property_city-145' );
$data_string = json_encode($data);
// create the options starting with basic authentication
curl_setopt($process, CURLOPT_USERPWD, $username . ":" . $password);
curl_setopt($process, CURLOPT_TIMEOUT, 30);
curl_setopt($process, CURLOPT_POST, 1);
// make sure we are POSTing
curl_setopt($process, CURLOPT_CUSTOMREQUEST, "POST");
// this is the data to insert to create the post
curl_setopt($process, CURLOPT_POSTFIELDS, $data_string);
// allow us to use the returned data from the request
curl_setopt($process, CURLOPT_RETURNTRANSFER, TRUE);
// we are sending json
curl_setopt($process, CURLOPT_HTTPHEADER, array(                                                                          
    'Content-Type: application/json',                                                                                
    'Content-Length: ' . strlen($data_string))                                                                       
);
// process the request
$return = curl_exec($process);
curl_close($process);
// This buit is to show you on the screen what the data looks like returned and then decoded for PHP use
echo '<h2>Results</h2>';
print_r($return);
echo '<h2>Decoded</h2>';
$result = json_decode($return, true);
echo "<pre>";print_r($result);

此处还有PROPERTY帖子类型自定义元字段或元框。我希望通过API

插入它的值

Property Post Type

0 个答案:

没有答案