Response while get method via API:
"id":"12680",
"title": "TESTING Property",
"content": "Description of the property 123",
"status": "publish",
"property_meta": {
"fave_currency_info": [
""
],
"fave_property_price": [
"320000"
],
"fave_property_price_postfix": [
"Sq Ft"
],
"fave_property_sec_price": [
"1500"
]
}
**Auth **: basic auth **Body **: raw data =>
{
"title": "Test New Moulee Property",
"content": "Description of the property",
"status": "publish",
"property_meta":
{
"fave_fave_property_price":["3511111"],
"fave_property_price_prefix":["586776"],
"fave_property_price_postfix" : ["7888877"],
"fave_property_size" : ["65"],
"fave_property_size_prefix" : ["4666"]
}
}
Method : Post
Response while post method via API:
"id":"12677",
"title": "Test New Moulee Property",
"content": "Description of the property",
"status": "publish",
"property_meta": {
"fave_property_price": [
""
],
"fave_property_price_postfix": [
""
],
"fave_property_sec_price": [
""
]
}
Actual Issues is while adding the record in wordpress(houzez theme) via postman api, It will create a record successfully, But in the record values there is an empty values occur in property_meta field.
we are expecting the property_meta field values also need to add in it.
This is the postman collection which I've tried via API.
/*------------------------------------------------
* Properties Meta Fields for rest API
*----------------------------------------------- */
if( !function_exists('houzez_property_rest_api_field')) {
add_action( 'rest_api_init', 'houzez_property_rest_api_field' );
function houzez_property_rest_api_field() {
register_rest_field( 'property', 'property_meta', array(
'get_callback' => 'houzez_get_rest_api_property_meta'
) );
}
function houzez_get_rest_api_property_meta( $object ) {
$post_id = $object['id'];
$property_meta = get_post_meta( $post_id );
// add filter
$property_meta = apply_filters( 'houzez_property_rest_api_meta', $property_meta );
// return meta
return $property_meta;
}
}
In your POST request, you're using meta field names like fave_fave_property_price, fave_property_price_prefix, etc. However, in your GET response, the names are slightly different e.g., fave_property_price, fave_property_price_postfix