Support

Account

Home Forums Front-end Issues Conditional logic for user custom fields – author.php

Solved

Conditional logic for user custom fields – author.php

  • Hi everyone, how can i manage the conditional logic for user custom fields on the author.php page?

    <?php if( get_the_author_meta(“user-facebook”, true) ): ?>
    <h5><?php the_field(‘user-facebook’); ?></h5>
    <?php else: ?>
    // do something else
    <?php endif; ?>

    Many thanks!
    n.

  • Hi nicoloaversa! Try this:

    
    <?php
    // get current author object
    $curauth = (isset($_GET['author_name'])) ? get_user_by('slug', $author_name) : get_userdata(intval($author));
    $author_id = $curauth->ID;
    
    $user_facebook = get_field('user-facebook', 'user_'.$author_id); // see https://www.advancedcustomfields.com/resources/how-to-get-values-from-a-user/
    
    if( $user_facebook ): ?>
    
    <h5><?php echo $user_facebook; ?></h5>
    
    <?php else: ?>
    // do something else
    <?php endif; ?>
    
Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.