我正在尝试从REST API创建自定义的Post-Type"属性"。我能够成功地创建它,我刚刚传递了标题和内容。但是我也想将值插入诸如城市,价格,类型,状态国家之类的元框。这些是Houzez主题的一部分。如何使用所有这些值创建此帖子类型属性?请建议。
这是我现在的代码。请建议添加什么。
<?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);
也是属性帖子类型自定义元字段或元框。我想通过API
插入它的值属性帖子类型
说明如何在Houzez中添加元数据支持的说明,最初的想法是:
如何在WordPress API帖子中包括元字段?
您需要设置:
- 'show_in_rest'true当register_post_type()
- 'custom-fields'必须在"支持"时处于"支持"时
- 'show_in_rest'true当register_meta()
进行这些修改时,您必须考虑:
- 不要直接修改主题和/或插件,因为更新您丢失了修改
- 只需要添加您需要的东西,仅需
在文件夹示例/中,您可以在不同的主题和插件中找到示例,此刻仅存在一个示例,但是将来我可以添加更多
Houzez
您必须激活儿童主题和儿童插件
houzez-child
路径:WP-CONTENT/主题
houzez儿童主题,在元字段中添加'show_in_rest'
houzez-theme-functionality-child
路径:wp-content/插件
儿童插件,添加"自定义场"以支持
文件在我的repo