How can I output a group field for current users
Support › MB User Meta › How can I output a group field for current users
- This topic has 1 reply, 2 voices, and was last updated 3 years ago by
Long Nguyen.
Viewing 2 posts - 1 through 2 (of 2 total)
-
AuthorPosts
-
April 8, 2022 at 3:47 PM #35537
jamesfosker
ParticipantI'm trying to retrieve my group field that I've added to the user profile with the user meta Addon, I'm trying to adapt output code that I've used before from a page meta but it's not working for user meta.
Please see my code below:
User Metabox:
<?php add_filter( 'rwmb_meta_boxes', 'am_dz_statement_metabox' ); function am_dz_statement_metabox( $meta_boxes ) { $prefix = ''; $meta_boxes[] = [ 'title' => __( 'Statements', 'your-text-domain' ), 'id' => 'statements', 'type' => 'user', 'fields' => [ [ 'name' => __( 'Statements', 'your-text-domain' ), 'id' => $prefix . 'am_statements', 'type' => 'group', 'collapsible' => true, 'clone' => true, 'sort_clone' => true, 'fields' => [ [ 'name' => __( 'Statememnt File', 'your-text-domain' ), 'id' => $prefix . 'AM_statment_file', 'type' => 'file_advanced', ], [ 'name' => __( 'Statement Title', 'your-text-domain' ), 'id' => $prefix . 'AM_statement_title', 'type' => 'text', ], ], ], ], ]; return $meta_boxes; }
Shortcode:
<?php add_shortcode('am_dz_statements', function() { $statements = rwmb_meta( 'statements', ['object_type' => 'user'], $user_id );//Slides needs to be var in the module if ( empty( $statememnts ) ) { return ''; } if ( ! empty( $group_values ) ) { foreach ( $group_values as $group_value ) { $value = isset( $group_value[$sub_field_key] ) ? $group_value[$sub_field_key] : ''; echo $value; // Display sub-field value } } $counter = 0; foreach ( $statements as $statement ) { $counter++; $statementfile = $statement['AM_statment_file']; $statementtitele = $statement['AM_statement_title']; $output .= '<div id="am-statement-' . $counter .'" class="am-statement">'; $output .= '<h2 class="fm-slide-title">'; $output .= '<a href="' . . '">' . $statementtitele . '</a>'; $output .= '</h2>'; $output .= '</div>'; } return $output; } );
April 9, 2022 at 6:42 AM #35544Long Nguyen
ModeratorHi James,
You can use the WP function get_current_user_id() to get the current user ID and pass to the helper function. For example:
$current_user_id = get_current_user_id(); $statements = rwmb_meta( 'statements', ['object_type' => 'user'], $current_user_id );//Slides needs to be var in the module
-
AuthorPosts
Viewing 2 posts - 1 through 2 (of 2 total)
- You must be logged in to reply to this topic.