• How can i add a custom field to the event-editor.php field.

    I’ve already done a copy of this file in my theme and now i need to add some custom fileds to the form.

    Thanks.

Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter carlosmarugan

    (@carlosmarugan)

    I managed to display it with the following code:

    <div class="input">
    <label for="duracion-espectaculo"><?php esc_html_e( 'Duración del Espectáculo', 'text-domain' ); ?></label>
    <input type="number" name="duracion_espectaculo" id="duracion-espectaculo" value="<?php echo esc_attr( get_field('duracion_espectaculo', $EM_Event->post_id) ); ?>" > HORAS
    </div>

    But now i can’t get to save the changes.
    I don’t receive any error message but the changes don’t save.

    Any ideas?

    Thanks

    If you don’t call update_field, the value won’t be saved. You could use the em_event_get_post filter to pick up the value of $_POST[‘duracion_espectaculo’] and save the value using update_field.

    add_filter( 'em_event_get_post', 'my_event_get_post', 10, 2 );
    function my_event_get_post($result, $EM_Event) {
        if ( ! empty( $_POST['duracion_espectaculo'] ) ) {
            update_field( 'duracion_espectaculo', $_POST['duracion_espectaculo'], $EM_Event->post_id);
        }
        return $result;
    }
    Thread Starter carlosmarugan

    (@carlosmarugan)

    Thanks @joneiseman

    Where do i have to add this code exactly? In the functions file or in the event-editor file.

    You can add this using the Code Snippets plugin

    • This reply was modified 1 year, 2 months ago by joneiseman.
Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Add custom field to event form’ is closed to new replies.