function houzez_custom_post_type_args( $args, $post_type ) {
if ( $post_type === 'property' ) {
$args['show_in_rest'] = true;
$args['rest_base'] = 'property'; // specify hard to avoid issues with route URLs on local and live sites
}
return $args;
}
add_filter( 'register_post_type_args', 'houzez_custom_post_type_args', 20, 2 );
function prop_update_crm_property_multiple_terms() {
$fields = array(
'property_feature',
'property_status'
);
foreach ($fields as $field) {
register_rest_field( 'property',
$field,
array(
'get_callback' => function ( $post, $field_name, $request ) {
$terms_id = wp_get_post_terms( $post['id'], $field_name );
$arr = array();
foreach ($terms_id as $term_id) {
$term = get_term($term_id, $field_name);
array_push($arr, $term->name);
}
return $arr;
},
'update_callback' => function ( $value, $post, $field_name ) {
return wp_set_object_terms( $post->ID, $value, $field_name );
},
'schema' => array(
'type' => 'array'
)
)
);
}
}
add_action( 'rest_api_init', 'prop_update_crm_property_multiple_terms' );