Support

Account

Home Forums Front-end Issues Error trying to out File field on front end

Solving

Error trying to out File field on front end

  • I have created a custom “File” field for user profiles named “attachment”.

    I’m now trying to output the filename and URL of the File field on the front end, for the currently logged in user. This is the code I’m using, pulled from the official documentation page for the File field, plus another forum post about pulling fields for the current user is:

    
    <?php 
    if ( is_user_logged_in() ) :
    
    	$user_id = get_current_user_id();
    	$file = get_field( 'attachment', "user_".$user_id );
    	if($file): ?>
        <a href="<?php echo $file['url']; ?>"><?php echo $file['filename']; ?></a>
    	<?php endif;
    
    endif;
    
    ?>
    

    On the front end, it returns the error:
    Warning: Illegal string offset ‘filename’ in /home/jxj2goc/public_html/wp-content/themes/bricks/includes/elements/code.php(157) : eval()’d code on line 8
    h

    Anyone know how to fix this?

  • This reply has been marked as private.
  • OK figured it out. Need to set field’s return value to “File array”.

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.