Support

Account

Home Forums General Issues Load default value (time picker field) from Relationship field

Solved

Load default value (time picker field) from Relationship field

  • Hi!
    I have two CPT (Podcast and Programs) conected with a Relationship field (‘podcast-programa’). Each program has a time picker field with the starting time of the show (‘hora de inicio’). What I need is that when creating a new Podcast and selecting its related Program, the field of the starting time of the podcast (‘podcast_hora_inicio’, also a time picker field) shows as default value the starting time of the related program.

    This is what I tried, but it’s not working:

    add_action('acf/load_field/name=podcast_hora_inicio', 'hora_inicio_podcast');
    function hora_inicio_podcast($field){
    
    $programas = get_field('podcast_programa');
    
    if( $programas ): 
        foreach( $programas as $programa ):
            $horapInicio = get_post_meta($programa->ID, 'hora_de_inicio', true);
    		$field['default_value'] = $horapInicio;
    	return $field;
        endforeach;
    endif;
    }

    Thanks in advance!

  • This code worked for me:

    function hora_inicio_podcast( $field ) {
    $programas = get_field('podcast_programa');
    if( $programas ): 
        foreach( $programas as $programa ):
            $horapInicio = get_post_meta($programa->ID, 'hora_de_inicio', true);
    		$fecha = date("s:i:H", $horapInicio);
    	$field['default_value'] = $fecha;
         return $field;
        endforeach;
    endif;
    return $field;*/
    }
    
    add_filter('acf/load_field/name=podcast_hora_inicio', 'hora_inicio_podcast');
Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.