Home Forums General Issues the_sub_field is returning unwanted information Reply To: the_sub_field is returning unwanted information

  • the_sub_field('file_attachment') gets the same thing that get_sub_field('file_attachment'); returns. The only difference is that the_sub_field() echos the value, in this case a stringified array, and get_sub_field() returns the array. If you want to echo the file name then you need to echo the title array element, or one of the other array elements for other things

    		// check if the repeater field has rows of data
    		if( have_rows('attachments') ):
    		 	// loop through the rows of data
    		    while ( have_rows('attachments') ) : the_row();
    		        // display a sub field value
    		        $file = get_sub_field('file_attachment');
    		        if( $file ):
    		        <a target="_blank" href="<?php echo $file['url']; ?>"><?php echo $file['title']; ?></a>
    		        <?php endif;
    		else :
    		    // no rows found