Home / Admin / MemberPress: Add Custom Field Date to Members Table
Duplicate Snippet

Embed Snippet on Your Site

MemberPress: Add Custom Field Date to Members Table

This code snippet will add data collected through a custom field on MemberPress registration forms to the members' table at Dashboard > MemberPress > Members. The data will be added to the new custom column.

To use this code snippet, a custom field should be created at Dashboard > MemberPress > Settings > Fields tab.

Code Preview
php
<?php
function custom_admin_members_col($cols) {
  $cols['business_name'] = __('Business Name', 'memberpress'); // Replace the business_name with the name of the actual custom field key & replace the dummy Business Name text with the name of the actual custom field 
  return $cols;
}
add_filter('mepr-admin-members-cols', 'custom_admin_members_col');
function custom_admin_members_col_content($attributes, $rec, $column_name, $column_display_name) {
  if($column_name == 'business_name') { // Replace the business_name with the actual custom field key
    $user = get_user_by('login', $rec->username);
    $business_name = get_user_meta($user->ID, 'mepr_business_name', true); // Replace the dummy mepr_business_name slug with the actual custom field slug
  }
  ?>
    <td <?php echo $attributes; ?>><?php echo $business_name; ?></td>
  <?php
}
add_filter('mepr_members_list_table_row', 'custom_admin_members_col_content', 10, 4);

Comments

Add a Comment