I have a repeatable field in a wordpress custom post type that is linked to another wordpress custom post type. I want to loop through the repeatable field and then for each field access the data from the linked post type. The first result is returned, but on the second I get the following error:
Fatal error : [] operator not supported for strings.
I tried removing the brackets from my variables like $staff = $coach['team_staff'] but that did not work.
I also tried setting $staff = array(); before the loop and that did not work.
Not sure what I have wrong here:
global $post;
// Get The Staff Members
$coaches = get_post_meta($post->ID, 'repeatable_fields', true);
if ( $coaches ) :
foreach ( $coaches as $coach ) :
$staff[] = $coach['team_staff'];
$role[] = $coach['team_role'];
// Loop through each staff member
foreach( $staff as $index => $staff ) :
$args = array (
'post_type' => 'staff',
'title' => $staff
);
$posts = get_posts( $args );
foreach ( $posts as $post ) : setup_postdata ( $post );
// get post meta here
endforeach;
endforeach;
endforeach;
endif;