How to Update Related Meta in JetEngine Using JetFormBuilder Post Action Hook
Description
Learn how to dynamically update related meta fields in JetEngine using a custom Post Action hook in JetFormBuilder.
In this step-by-step tutorial, we walk you through the process of configuring a WordPress hook, using $wpdb to update database values, and ensuring seamless integration between JetEngine relations and JetFormBuilder forms.
???? What you’ll learn:
Setting up a custom action hook in JetFormBuilder.
Using the $wpdb class to update meta fields.
Debugging and ensuring a smooth implementation.
???? Resources:
https://jetformbuilder.com/features/jetformbuilder-connecting-wordpress-related-items-with-post-submit-actions/
https://crocoblock.com/knowledge-base/tips-and-tricks/cannot-display-relations-meta-field-in-the-add-new-post-form/
Jetformbuilder Update Field (plugin)
https://github.com/ihslimn/jet-form-builder-update-field
Hook to update Relations Meta:
add_action('jet-form-builder/custom-action/edit_related_meta', function($request, $action_handler) {
global $wpdb;
// Nombre de la tabla (ajusta si tiene prefijo)
$table_name = $wpdb->prefix . 'jet_rel_12_meta';
// Validar que los datos necesarios están presentes
if (isset($request['service_meta_id']) && isset($request['service_comment'])) {
$meta_id = intval($request['service_meta_id']); // ID del meta a actualizar
$meta_value = sanitize_text_field($request['service_comment']); // Valor a asignar al campo meta_value
// Actualizar el campo 'meta_value' en la tabla
$wpdb->update(
$table_name,
['meta_value' => $meta_value], // Campos a actualizar
['_ID' => $meta_id], // Condición (WHERE)
['%s'], // Formato del valor actualizado
['%d'] // Formato del valor de la condición
);
}
}, 10, 2);
???? Boost your Crocoblock skills and take your WordPress projects to the next level with this practical guide.