I created a group in ACF as follows:
1 – Relationship (casting_1)
2 – Function : (casting_role_1)
3 – Relationship (casting_2)
4 – Function : (casting_role_2)
Repeat these values from 1 to 10
casting_1, casting_2, casting_role_1, casting_role_2 etc
I know I can return the values as follows:
<?php if ( have_rows( 'casting_group' ) ) : ?>
<?php while ( have_rows( 'casting_group' ) ) : the_row(); ?>
<?php $casting_1 = get_sub_field( 'casting_1' ); ?>
<?php if ( $casting_1 ) : ?>
<a href="<?php echo get_permalink( $casting_1 ); ?>"><?php echo get_the_title( $casting_1 ); ?></a>
<?php endif; ?>
<?php the_sub_field( 'casting_role_1' ); ?>
<?php $casting_2 = get_sub_field( 'casting_2' ); ?>
<?php if ( $casting_2 ) : ?>
<a href="<?php echo get_permalink( $casting_2 ); ?>"><?php echo get_the_title( $casting_2 ); ?></a>
<?php endif; ?>
<?php endwhile; ?>
<?php endif; ?>
this way the code will be huge because I will have to repeat it for + 50 values.
I need to customize values so i use the while to manage it
if( have_rows('casting_group') ):
while( have_rows('casting_group') ): the_row();
if( $subfields = get_row() ) { ?>
<?php
foreach ($subfields as $key => $value) {
if ( !empty($value) ) { $field = get_sub_field_object( $key ); ?>
<?php
$castImg = get_the_post_thumbnail_url($value, 'THUMB_150X150');
$castLink = get_permalink($value);
$castTitle = get_the_title($value);
} ?>
<a href="<?php echo $castLink ?>"><img src="<?php echo $castImg ; ?> "/><?php echo $castTitle ?></a>
<?php }
}
endwhile;
endif;
the problem is that I can’t return the value of casting_role.
What I would like is to look like this:
— Casting 1: $value1 for casting_1// img, permalink etc.
— Casting Role 1: $value1 for casting_role_1 (text)
— Casting 2: $value2 for casting_role_2 // img, permalink etc.
— Casting Role 2: $value2 for casting_role_2 (text)
And so on.
Can you help me on this?
Get and loop values from acf fields group