Ecommerce Shopify WordPress Discussion

How to pass the values into META field "property_meta" via api in WordPress for (Houzez theme)

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. https://special-task-force.postman.co/workspace/Zoho-CRM-to-Wordpress~3cd6acb9-4e6a-457d-aba1-fe1aa7a10619/collection/25739789-0b8c76f0-d441-4f01-baca-58fd062a4407?action=share&creator=31749745 /*------------------------------------------------ * 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 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', 'update_callback' => 'houzez_update_rest_api_property_meta', 'schema' => null, )); } function houzez_get_rest_api_property_meta( $object ) { $post_id = $object['id']; $property_meta = get_post_meta( $post_id ); $property_meta = apply_filters( 'houzez_property_rest_api_meta', $property_meta ); return $property_meta; } function houzez_update_rest_api_property_meta($value, $object, $field_name) { if (!is_array($value) || !$object instanceof WP_Post) { return; } foreach ($value as $meta_key => $meta_value) { update_post_meta($object->ID, $meta_key, $meta_value); } } }

January 20, 2024

TurboCommerce make the better internet purchasing globaly

Turbo Multi-language Translator

Make the better internet purchasing globaly

Turbosify SEO Speed Booster

5.0 (7) Free plan available
Get better conversions by improving store loading speed Installed

Turbo Multi-language Chat - AI Customer service in one hand

TurboCommerce make the better internet purchasing globaly
Our products

The help you need, when you need it

App by Turbo Engine

3 apps • 5.0 average rating

Turbosify Speed Booster

5.0 (7)
Get better conversions by optimizing shopify store Google page speed Installed

Turbosify Translator for Wordpress Woocommerce

5.0 (74) Free Wordpress Woocommerce Plugin
Translate your wordpress website to multiple language within 1 click, no configuration needed, no No technical required

Grow your business here

Whether you want to sell products down the street or around the world, we have all the tools you need.