Group field
- This topic has 11 replies, 2 voices, and was last updated 3 years ago by Yasmine. 
- 
		AuthorPosts
- 
		
			
				
October 14, 2022 at 9:39 PM #38664Yasmine ParticipantHi Long, I am struggling with groups again. I have tried to use the documentation on this page. I am getting a fatal error with the following. What am I doing wrong? add_action( 'transition_post_status', 'invite_email_sent_to_coauthor', 10, 3); function invite_email_sent_to_coauthor( $new_status, $old_status, $post ) { $co_author_group = rwmb_meta( 'academicadd_co_author' ) ?: []; //this is the group field id foreach ( $co_author_groups as $co_author_group ) { $send_email_y = $co_author_group ['academicco-author_lead_yn'] ?? ''; //this is the id of a field within the group field $coauthor_email = $co_author_group ['academicco-author_email'] ?? ''; //was I supposed to include this part: ?? '' or replace it with something? $academic_name = $co_author_group ['academicco-author_full_name'] ?? ''; }; if (( $new_status == 'publish') && ($old_status !== 'publish') && (get_post_type( $post ) == 'research') && (!empty($coauthor_email)) && ($send_email_y == 'y'))); {.... }October 15, 2022 at 8:57 AM #38665Long Nguyen ModeratorHi, Can you please share the fatal error message? You can pass the post ID to the helper function to get the field value. For example $co_author_group = rwmb_meta( 'academicadd_co_author', '', $post->ID );October 15, 2022 at 2:33 PM #38668Yasmine 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 15, 2022 at 2:37 PM #38669Yasmine ParticipantAnd I just tried $co_author_group = rwmb_meta( 'academicadd_co_author', '', $post->ID );but got the same error too!October 15, 2022 at 4:26 PM #38672Yasmine ParticipantA follow up question - in my IF statement, where I want to check a custom fields value is equal to 'y'. Have I done this correctly? I have another piece of code and it works when I don't query against the value of a custom field, but when I try to query that it equals a custom field value it returns and does not execute my code (even though I checked and the value is definitely correct) October 16, 2022 at 9:29 PM #38686Long Nguyen ModeratorHi, It looks like there is an issue with your custom code, not with the helper function rwmb_meta(). If you want to do a customization job with an extra fee, please contact us via this form https://metabox.io/contact/, our plugin will help you to do that.October 17, 2022 at 1:26 PM #38700Yasmine ParticipantOk Long, thank you for the clarification. And my second question - how do you add custom fields to if statements? Can I do it like: $co_author_email = rwmb_meta( 'academicadd_co_author', '', $post->ID ) If ($co_author_email == 'y')This is for something else, and the code works perfectly if no custom field conditions in the if statement, but then adding custom field conditions into if statements stops it from executing, even though the value is definitely there October 17, 2022 at 11:34 PM #38717Long Nguyen ModeratorHi, Which is the field type add_co_author? If it is a simpletextorselectfield, you can check the field value as well. And please correct theifstatement,ishould be in lowercase.$co_author_email = rwmb_meta( 'academicadd_co_author', '', $post->ID ); if ( $co_author_email == 'y' ) { echo "Yes"; }October 17, 2022 at 11:45 PM #38718Yasmine ParticipantHey long, the field I am actually having issues with is a radio field with the values 0 and 1. I was trying with rwmb_metain exactly the format you share, however I thought maybe I should be using a different filterOctober 17, 2022 at 11:56 PM #38719Yasmine Participant$checked_box = rwmb_get_value('hidden_published_already', '', $post->ID ); if (( $new_status == 'publish') && ($old_status != 'publish') && (get_post_type( $post ) == 'research') && (($checked_box == 'Not published') || ($checked_box == 0))){ ..}// 0 is the value of unpublishedThis is what I have. It either works, or it doesn't work. It doesn't work if I use === 0, but it does work if I use ==0. The issue is, using == 0 also means it fires when the value is 1 October 17, 2022 at 11:57 PM #38720Yasmine ParticipantSorry in above it just shows the different filters I tried. Also tried: $checked_box = rwmb_meta('hidden_published_already', '', $post->ID ); if (( $new_status == 'publish') && ($old_status != 'publish') && (get_post_type( $post ) == 'research') && ($checked_box == 0)){October 18, 2022 at 12:06 AM #38721Yasmine ParticipantOh I think I worked it out - the above was my first attempt using the label, not the value - and I think that is what was wrong! 
- 
		AuthorPosts
- You must be logged in to reply to this topic.