Support » Plugin: Ultimate Member – User Profile, User Registration, Login & Membership Plugin » Conditional Logic Surround Fields in Directory Template

  • Resolved Chris

    (@lamordnt)


    How would I go about adding conditional logic to custom fields on a custom directory template? Below is what I am trying to accomplish with no luck:

    <li class="fas fa-phone"><?php $mobile_number = um_user('mobile_number');if (!empty($mobile_number)) {?> <li class="fas fa-phone"><code>user.mobile_number</code></li> <?php } ?>

    So if the custom field has content then it should show that field. Any thoughts on this?

    • This topic was modified 1 month, 2 weeks ago by Chris.
    • This topic was modified 1 month, 2 weeks ago by Chris.
    • This topic was modified 1 month, 2 weeks ago by Chris.
Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Contributor Champ Camba

    (@champsupertramp)

    Hi @lamordnt

    Where specifically do you add that code?

    Regards,

    Thread Starter Chris

    (@lamordnt)

    I am using this in a custom directory template. Here is an example on pastebin: https://pastebin.com/Ewntvcqa

    You can see on line 25 where I am trying to apply the conditional logic to the mobile_number custom field. Thanks

    Plugin Contributor Champ Camba

    (@champsupertramp)

    Hi @lamordnt

    You need to append it in the member directory results before you can bind it to the front-end with javascript.

    PHP:

    add_filter("um_ajax_get_members_data","um_0303212_profile_avatar_members_data", 10, 3 );
    function um_0303212_profile_avatar_members_data( $data_array, $user_id, $directory_data ){
    
        $data_array['mobile_number'] = um_user("mobile_number");
        
        return $data_array;
    
    }

    Template:

    <tr>
        <td><code>user.display_name_html</code></td>
        <td><code>user.phone_number</code></td>
        <# if ( user.mobile_number != '' ) { #>
           <td><code>user.mobile_number</code></td>
        <# } #>
        <td><code>user.user_email</code></td>
        <td><code>user.community_address</code></td>
    </tr>
    

    Regards,

    Thread Starter Chris

    (@lamordnt)

    Exactly what I needed, thank you for the timely support.

Viewing 4 replies - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.