Title: Echo when certainfield is not empty
Last modified: June 15, 2022

---

# Echo when certainfield is not empty

 *  [arjanwit](https://wordpress.org/support/users/arjanwit/)
 * (@arjanwit)
 * [4 years ago](https://wordpress.org/support/topic/echo-when-certainfield-is-not-empty/)
 * Hi,
    On my website I am using wp members plugin. I want to only display some 
   content when a custom field is not empty. Field is called wpmem_rnr. It is hidden
   during registration and can be filled by an admin. Using the shortcode [wpmem_field
   field=”wpmem_rnr”] will show the field to the loggedin user. Now I want to echo
   a specific text, only when this field is filled. I was using:
 *     ```
       function show_coin () {
         if( get_field('wpmem_rnr') ) {
       	  echo get_field('wpmem_rnr') . ' Ja het werkt' ;
         }
       }
       ```
   
 * But this does not do the trick.
 * Any help will be appreciated.
    Regards, Arjan

Viewing 1 replies (of 1 total)

 *  Plugin Author [Chad Butler](https://wordpress.org/support/users/cbutlerjr/)
 * (@cbutlerjr)
 * [4 years ago](https://wordpress.org/support/topic/echo-when-certainfield-is-not-empty/#post-15740552)
 * There is in fact a `get_field()` function in WP, but that is not at all how it
   is used (it’s for post information, not users).
 * The function you’re looking for would be WP’s `get_user_meta()` which retrieves
   user meta (all WP-Members custom fields are going to be user meta in WP’s db 
   schema).
 * The [`get_user_meta()`](https://developer.wordpress.org/reference/functions/get_user_meta/)
   function needs the field meta key (‘wpmem_rnr’ in your case), but it also needs
   the user ID. Depending on how/where you’re using this, you’ll need to consider
   if the user is the currently logged in user (in which case you can use WP’s [`get_current_user_id()`](https://developer.wordpress.org/reference/functions/get_current_user_id/)),
   or if you need to pick up the user ID from somewhere else. I’m going to assume
   you’re displaying to the currently logged in user:
 *     ```
       function show_coin() {
           $user_id = get_current_user_id();
           $field = get_user_meta( $user_id, 'wpmem_rnr', true );
           if ( $field && '' != $field ) {
               echo $field . ' Ja het werkt';
           }
       }
       ```
   
 * Alternative to using `get_user_meta()`, WP-Members has an API function [`wpmem_get_user_meta()`](https://rocketgeek.com/plugins/wp-members/docs/api-functions/wpmem_get_user_meta/)
   which always passes “true” for `get_user_meta()`‘s `$single` parameter (since
   any field data WP stores is going to be `$single = true`. This allows you to 
   shorthand the usage by one less argument in the function:
 *     ```
       function show_coin() {
           $user_id = get_current_user_id();
           $field = wpmem_get_user_meta( $user_id, 'wpmem_rnr' );
           if ( $field && '' != $field ) {
               echo $field . ' Ja het werkt';
           }
       }
       ```
   
    -  This reply was modified 4 years ago by [Chad Butler](https://wordpress.org/support/users/cbutlerjr/).

Viewing 1 replies (of 1 total)

The topic ‘Echo when certainfield is not empty’ is closed to new replies.

 * ![](https://ps.w.org/wp-members/assets/icon-256x256.png?rev=1226414)
 * [WP-Members Membership Plugin](https://wordpress.org/plugins/wp-members/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/wp-members/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/wp-members/)
 * [Active Topics](https://wordpress.org/support/plugin/wp-members/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/wp-members/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/wp-members/reviews/)

 * 1 reply
 * 2 participants
 * Last reply from: [Chad Butler](https://wordpress.org/support/users/cbutlerjr/)
 * Last activity: [4 years ago](https://wordpress.org/support/topic/echo-when-certainfield-is-not-empty/#post-15740552)
 * Status: not resolved