function get_custom_field_value() { $post_id = intval($_POST['post_id']); $field_name = sanitize_text_field($_POST['field_name']); echo get_post_meta($post_id, $field_name, true); wp_die(); } add_action('wp_ajax_get_custom_field_value', 'get_custom_field_value'); function update_custom_field_value() { $post_id = intval($_POST['post_id']); $field_name = sanitize_text_field($_POST['field_name']); $field_value = sanitize_text_field($_POST['field_value']); update_post_meta($post_id, $field_name, $field_value); wp_die(); } add_action('wp_ajax_update_custom_field_value', 'update_custom_field_value');