Skip to content

Instantly share code, notes, and snippets.

@dantetesta
Created February 22, 2024 16:00
Show Gist options
  • Save dantetesta/c26f1d6502c3baf3989aa13f08cd2722 to your computer and use it in GitHub Desktop.
Save dantetesta/c26f1d6502c3baf3989aa13f08cd2722 to your computer and use it in GitHub Desktop.
Slug Update JetFormBuilder Call a Hook
/*
Crie um campo de texto chamado slug
Adicione um call a hook notification -- jet-form-builder/custom-filter/save-slug
*/
add_action( 'jet-form-builder/form-handler/after-insert-post', function( $data ) {
// Certifique-se de que o campo 'slug' está presente nos dados enviados
if ( ! empty( $data['slug'] ) ) {
$slug = sanitize_title( $data['slug'] );
// Atualiza o post com o slug fornecido
wp_update_post( array(
'ID' => $post_id,
'post_name' => $slug, // WP usa 'post_name' para armazenar o slug
) );
}
}, 10, 3 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment