I'm trying to create custom post-type "property" from REST Api. And i'm able to create it successfully i just passed title and content. BUT i also want to insert the values to the meta boxes like CITY, Price, Type, Status Country. These are the part of HOUZEZ theme. How can i create this post type PROPERTY with all these values?? please suggest.
This is My Code as of now. Please suggest what to add.
<?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);
also here is the PROPERTY post type custom meta fields or meta boxes. for which i want to insert the values of it through API
Explanation of how to add metadata support in houzez, the original idea is:
How to include META fields in Wordpress API Post?
You need to set:
When you do these modifications you must think in:
In the folder example/, you can find examples in different themes and plugins, at this moment only exist one example but in the future, I can add more
houzez
You must activate the child theme and child plugin
houzez-child
path: wp-content/themes
houzez child theme, add 'show_in_rest' in meta fields
houzez-theme-functionality-child
path: wp-content/plugins
child plugin, add 'custom-fields' to support
The files are in my repo