Group field

Support MB Group Group fieldResolved

Viewing 12 posts - 1 through 12 (of 12 total)
  • Author
    Posts
  • #38664
    YasmineYasmine
    Participant

    Hi 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')));
    {.... }
    #38665
    Long NguyenLong Nguyen
    Moderator

    Hi,

    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 );

    #38668
    YasmineYasmine
    Participant

    Warning: 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.

    #38669
    YasmineYasmine
    Participant

    And I just tried $co_author_group = rwmb_meta( 'academicadd_co_author', '', $post->ID ); but got the same error too!

    #38672
    YasmineYasmine
    Participant

    A 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)

    #38686
    Long NguyenLong Nguyen
    Moderator

    Hi,

    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.

    #38700
    YasmineYasmine
    Participant

    Ok 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

    #38717
    Long NguyenLong Nguyen
    Moderator

    Hi,

    Which is the field type add_co_author? If it is a simple text or select field, you can check the field value as well. And please correct the if statement, i should be in lowercase.

    $co_author_email = rwmb_meta( 'academicadd_co_author', '', $post->ID );
    
    if ( $co_author_email == 'y' ) {
        echo "Yes";
    }
    #38718
    YasmineYasmine
    Participant

    Hey long, the field I am actually having issues with is a radio field with the values 0 and 1.

    I was trying with rwmb_meta in exactly the format you share, however I thought maybe I should be using a different filter

    #38719
    YasmineYasmine
    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 unpublished

    This 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

    #38720
    YasmineYasmine
    Participant

    Sorry 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)){
    #38721
    YasmineYasmine
    Participant

    Oh 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!

Viewing 12 posts - 1 through 12 (of 12 total)
  • You must be logged in to reply to this topic.