Forum Replies Created
-
AuthorPosts
-
Yasmine
ParticipantAnd I just tried
$co_author_group = rwmb_meta( 'academicadd_co_author', '', $post->ID );but got the same error too!Yasmine
ParticipantWarning: Invalid argument supplied for foreach() in /home/customer/www/acume.org/public_html/wp-content/themes/hello-elementor-child/functions.php on line 547 //Line 547 is foreach ( $co_author_groups as $co_author_group ) {
Fatal error: Uncaught Error: Object of class WP_User could not be converted to string in /home/customer/www/acume.org/public_html/wp-content/themes/hello-elementor-child/functions.php:563 Stack trace: #0 /home/customer/www/acume.org/public_html/wp-includes/class-wp-hook.php(307): academic_invite_coauthor_to_acume('trash', 'pending', Object(WP_Post)) #1 /home/customer/www/acume.org/public_html/wp-includes/class-wp-hook.php(331): WP_Hook->apply_filters(NULL, Array) #2 /home/customer/www/acume.org/public_html/wp-includes/plugin.php(476): WP_Hook->do_action(Array) #3 /home/customer/www/acume.org/public_html/wp-includes/post.php(5303): do_action('transition_post...', 'trash', 'pending', Object(WP_Post)) #4 /home/customer/www/acume.org/public_html/wp-includes/post.php(4563): wp_transition_post_status('trash', 'pending', Object(WP_Post)) #5 /home/customer/www/acume.org/public_html/wp-includes/post.php(4775): wp_insert_post(Array, false, true) #6 /home/customer/www/acume.org/public_html/wp-includes/post.php(3575): wp_update_post( in /home/customer/www/acume.org/public_html/wp-content/themes/hello-elementor-child/functions.php on line 563
There has been a critical error on this website. Please check your site admin email inbox for instructions.Learn more about troubleshooting WordPress.
October 10, 2022 at 2:03 PM in reply to: Outputting a different user meta photo from field group #38614Yasmine
ParticipantHi Long,
I just gave this a try - but same issue. It pulls the correct information and successfully populates the MB group skin. But then does not work when I add that group to a section on my single post template.
Many thanks,
YasmineOctober 10, 2022 at 2:51 AM in reply to: Outputting a different user meta photo from field group #38606Yasmine
ParticipantHi Long,
Thank you for the support!
I have managed to pull the name and photo to the meta box group now (had some help).
However, it now does not show the data on the single post type. It is just blank, even though it populates on the meta box group skin side. I did it using shortcodes.
//Just the name of co-author add_shortcode("get_co_user_name", function (){ global $post; $post_type = get_post_type($post->ID); if(is_singular() && "research" === $post_type) { $field_id = rwmb_get_value( "academicadd_co_author", $post->ID, false ); foreach($field_id as $user) {$user_name = get_userdata(intval($user['academicacademic_user_coauthor']))->display_name; return $user_name; }}}); //Avatar of co-author add_shortcode("get_co_user_avatar", function (){ global $post; $post_type = get_post_type($post->ID); if(is_singular() && "research" === $post_type) { $field_id = rwmb_get_value( "academicadd_co_author", $post->ID, false ); foreach($field_id as $user) {$avatar_url = get_avatar_url($user['academicacademic_user_coauthor']); $main_html_markup = "<img src='$avatar_url'>"; }; return $main_html_markup; }});Yasmine
ParticipantIgnore me - all fixed. It was just about using the "edited_user_role" and ignoring anything to do with administrator. Thank you
Yasmine
ParticipantHi Long,
Just tried it out with the
user_roleand theedited_user_role, but it didn't quite do as I need.As an administrator, I could see the custom field on my
customeruser, but also on theselleruser. I only want them to be seen by the administrator on the relevant user (so on customer, I just seen their fields and on seller I see the ones unique to them). This is only to make it easier to know which are available to them and should be edited. It's not an urgent task, means when I go in to make edits, I only see the custom fields that are relevant to them.Hope I clarified!
Many thanks,
YasmineOctober 3, 2022 at 9:15 PM in reply to: Outputting a different user meta photo from field group #38521Yasmine
ParticipantHi Long,
I am still a bit confused by this. I think it is because I am trying to get an array value of a field in a group. So three levels. I tried to pair the two tutorials. And came out with this, which does not work. Any idea what I am doing wrong?
add_shortcode( 'co_author_loop_photo', function() { $user_group = rwmb_meta( 'academicadd_co_author' ); $user_ids = $user_group['academic_user_coauthor'] ?? : []; foreach ( $user_ids as $user_id) { $coauthor_photo = rwmb_meta( 'custom_avatar', [ 'object_type' => 'user' ], $user_id ); return $coauthor_photo; }});Yasmine
ParticipantHi Long,
I checked this and now works perfectly! Thank you so much for your help!
Yasmine
Yasmine
ParticipantHi Long,
Also if you add a link to a heading, the same problem occurs (so not just the button).
Thank you for your help.
Kind regards,
YasmineYasmine
ParticipantAmazing. That did it, thank you!
Yasmine
ParticipantHi Long,
Here it is. You ask if it is cloneable, it wasn't. Should it not be an array then? I only thought it was an array as when I tried to output directly, the link only said 'array'!
[ 'name' => __( 'Upload Research Paper PDF', 'your-text-domain' ), 'id' => $prefix . 'pdf', 'type' => 'file', 'desc' => __( 'Optional<small>Upload a PDF to give readers an easy way to access your research</small>', 'your-text-domain' ), 'max_file_uploads' => 1, 'columns' => 6, 'multiple' => false, 'tab' => 'academicreference_builder', ],Yasmine
ParticipantHi Long,
I only have the issue when I use the URL. For example, in a button that then links to that URL. I am also able to output as text! But if I add the URL as a link then when that button is pressed it outputs as "array"
August 22, 2022 at 1:27 AM in reply to: Outputting a different user meta photo from field group #37959Yasmine
ParticipantPlease ignore (or delete) my top message, I sent too soon and it doesn't make sense. Here is my real question:
It makes sense to get_post_meta first (rather than user). And as a sequence do I -
1 get the group
2 get the subgroup
3. Get the userWhen I use a
userfield within a group, is that returned value the user's ID? If so that makes more sense how to proceed.And then if I want to get the users profile picture, is this section in the documentation correct? Would I get the user's avatar in the same way I would get an advanced image?
// Sub-field image_advanced. $image_ids = $group['images'] ?? []; if ( $image_ids ) { $output .= '<div class="my-images">'; foreach ( $image_ids as $image_id ) { $image = RWMB_Image_Field::file_info( $image_id, ['size' => 'my-image-size'] ); $output .= '<img src="' . $image['url'] . '" />'; } $output .= '</div>'; }My questions only continue as I am definitely still doing something very wrong.
August 22, 2022 at 1:15 AM in reply to: Outputting a different user meta photo from field group #37958Yasmine
ParticipantOh ok. So in essence there are 3 stages:
1 get the group
2 get the subgroup
3. Get the userIm a bit confused by the documentation, as it says to use
get_userdata- not for the first part, which makes complete sense to get the post's information first, but for the third part when I need to find the selected user, do I not useget_usermeta?add_shortcode( 'co_author_loop_photo', function() { $user = get_post_meta( 'academic_user_coauthor', get_queried_object_id() ); $coauthor = rwmb_meta( 'academicadd_co_author' ); $coauthor = $coauthors ?? []; foreach ( $coauthors as $coauthor ) { $coauthor_details = $coauthor['academic_user_coauthor'] ?? ''; $co_author_photos = get_userdata( $coauthor_details, $custom_avatar, false ); foreach ( $co_author_photos as $co_author_photo ) { $image = RWMB_Image_Field::file_info( $co_author_photo, array( 'size' => 'thumbnail' ) ); echo '<img src="' . $image['url'] . '">'; return $image; } });Yasmine
ParticipantThat's great thank you. I found one more issue. When I make a meta box group section with a photo. I get a real error that stops my single post template from fully functioning. Here is the group field code that caused this new error:
'name' => __( 'Add Co-Author', 'your-text-domain' ), 'id' => $prefix . 'add_co_author', 'type' => 'group', 'clone' => true, 'fields' => [ [ 'name' => __( 'Co-author Full Name', 'your-text-domain' ), 'id' => $prefix . 'co-author_full_name', 'type' => 'text', 'clone' => true, ], [ 'name' => __( 'Co-author Email', 'your-text-domain' ), 'id' => $prefix . 'co-author_email', 'type' => 'email', 'clone' => true, ], [ 'name' => __( 'Co-author - Lead_YN', 'your-text-domain' ), 'id' => $prefix . 'co-author_lead_yn', 'type' => 'radio', 'options' => [ 'y' => __( 'Lead author', 'your-text-domain' ), 'n' => __( 'Not lead author', 'your-text-domain' ), ], 'clone' => true, 'inline' => false, ], -
AuthorPosts