• Resolved alby54

    (@alby54)


    Hi, I managed to create a user custom field adding this code to my child functions.php

    <?php
       function custom_user_profile_fields($user) {  
    
        global $neu_utility;
    
        $gender= esc_attr(get_the_author_meta('user_gender', $user->ID));    
    
    ?>  
    
        <h3><?php _e('Dati aggiuntivi', 'your_domain'); ?></h3>  
    
        <table class="form-table">
           <tr>
               <th>
                   <label for="user_gender"><?php _e('Sesso', 'your_domain'); ?>
                   </label></th>
                <td>
                    <input type="radio" name="user_gender" value="Male" <?=($gender=='Male') ? 'checked="checked"':''?> >M<br/><br />
                    <input type="radio" name="user_gender" value="Female" <?=($gender=='Female') ? 'checked="checked"':''?> >F<br />
                </td>
            </tr>
        </table>  
    
    <?php  
    
    }  
    
    get_user_meta($user_id, 'user_gender', true);
    
    function save_custom_user_profile_fields($user_id) {  
    
        if (!current_user_can('edit_user', $user_id))  
    
            return FALSE;  
    
        update_usermeta($user_id, 'user_gender', $_POST['user_gender']);
    
    }  
    
    add_action('show_user_profile', 'custom_user_profile_fields');
    add_action('edit_user_profile', 'custom_user_profile_fields');
    add_action('personal_options_update', 'save_custom_user_profile_fields');
    add_action('edit_user_profile_update', 'save_custom_user_profile_fields');
    ?>

    Now what I would like to do is to place an if else statement in the header.php that checks if the user logged in is male or female. I’ve tried various things but none of them work.
    (the problem is that I don’t know how to retrieve the value of $gender)
    Any help will be highly appreciated, thx.

Viewing 1 replies (of 1 total)
  • Thread Starter alby54

    (@alby54)

    OK…..I’ve found a code that works.

    global $current_user;
    get_currentuserinfo();
       if ( $current_user->user_gender == 'Male' ) {
          echo "Do this";
       }
       elseif ( $current_user->user_gender == 'Female' ) {
          echo "Do that";
       }

    Thanks anyway

Viewing 1 replies (of 1 total)
  • The topic ‘user custom field value in a conditional statement’ is closed to new replies.