A
A
Alexander Osadchy2019-11-29 12:59:44
React
Alexander Osadchy, 2019-11-29 12:59:44

How to display sub_field ACF value?

I set up the contents of the columns in the admin panel (I display additional ACF fields).

If I just have extra. field (the_field) - then everything is displayed normally, but if I have a nested field, then the value of the field is not displayed. What could be the problem?

case 'data_starta' :
            $start = the_sub_field( "date_start", $post->ID );
            if ( empty( $start ) )
                echo __( 'Не указана' );
            else
                printf( $start );
        break;

Displays "Not Specified".

This is my field group:

<?php if ( have_rows( 'data_raspisanie_grafik' ) ) : ?>
  <?php while ( have_rows( 'data_raspisanie_grafik' ) ) : the_row(); ?>
    <?php the_sub_field( 'date_start' ); ?>
    <?php the_sub_field( 'duration' ); ?>
    <?php the_sub_field( 'end_date' ); ?>
    <?php the_sub_field( 'schedule' ); ?>
  <?php endwhile; ?>
<?php endif; ?>

But if it's just a field, not a group, then everything works fine...

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Osadchiy, 2019-11-29
@DELUX

Here it worked:

case 'data_starta' :


            if ( have_rows( 'data_raspisanie_grafik' ) ) :
                while ( have_rows( 'data_raspisanie_grafik' ) ) : the_row();
                    $start = get_sub_field( "date_start", $post->ID );
                if ( empty( $start ) )
                    echo __( 'Дата не указана' );
                else
                    printf( $start );
                endwhile;
            endif;

        break;

Thanks to everyone who cares!

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question