Support

Account

Home Forums Add-ons Repeater Field Get $_POST['acf'] value of repeater field in post object

Solved

Get $_POST['acf'] value of repeater field in post object

  • I want to get the saved repeater field data of a POST OBJECT but I don’t know how to get it when using $_POST['acf'].

    Within a template file I can use this:

    
    $measurement_client_object					        	= get_field_object('measurement_client');
    $measurement_client						    	        = get_field('measurement_client');
    $measurement_client_name                    	    	= get_the_title($measurement_client->ID);
    $measurement_client_street_and_number	               	= get_field('company_street_and_number', $measurement_client->ID);
    $measurement_client_postal_code			               	= get_field('company_postal_code', $measurement_client->ID);
    $measurement_client_city				              	= get_field('company_city', $measurement_client->ID);
    $measurement_client_phone_number		              	= get_field('company_phone_number', $measurement_client->ID);
    $measurement_client_website				             	= get_field('company_website', $measurement_client->ID);
    $measurement_client_email_addresses                     = get_field('company_email_addresses', $measurement_client->ID);
    $measurement_client_contacts			    	        = get_field('company_contacts', $measurement_client->ID);
    $measurement_client_locations			    	        = get_field('company_locations', $measurement_client->ID);
    $measurement_client_internal_note		    	        = get_field('company_internal_note', $measurement_client->ID);
    

    But I don’t know how to get the data using $_POST['acf'].

    
    // Send measurement report emails
    add_action('acf/save_post', 'yl_send_measurement_report_mail', 5);
    function yl_send_measurement_report_mail( $post_id ) {
    
    // Get submitted values.
    $values	= $_POST['acf'];
    
    $measurement_mail_report_recipients = $_POST['acf']['field_5f6d7d925b2fc'];
    
    $measurement_client	= $_POST['acf']['field_5e147914518a6']; // Post Object field in the current post
    $measurement_client_email_addresses	= REPEATER FIELD IN OTHER POST // A repeater field of the above Post Object, not visible in the current post
    
    if ( $measurement_client_email_addresses ) {
        $list = array();
        foreach( $measurement_client_email_addresses as $measurement_client_email_address ) {
            $list[] = $measurement_client_email_address['field_5e1452c41945c'];
        }
        $to = implode(',', $list);
    }
    

    I have tried:

    
    $measurement_client_email_addresses = $measurement_client['field_XXXX-of-the-post-object-repeater-field'];
    
    $measurement_client_email_addresses = get_field('company_email_addresses', $measurement_client->ID);
    
    $measurement_client_email_addresses = get_field('company_email_addresses', $measurement_client->$post_id);
    
    and so on and so on but noting....
    
    

    I hope my question is clear?

  • 
    $measurement_client	= $_POST['acf']['field_5e147914518a6']; // Post Object field in the current post
    

    The above value will be the post ID of the post, not an object

    
    $measurement_client_id = intval($_POST['acf']['field_5e147914518a6']);
    $measurement_client = get_post($measurement_client_id );
    
  • Thanks for your reply.

    I guess I’m not getting it completely..? I tried this:

    
    $measurement_client_id = intval($_POST['acf']['field_5e147914518a6']);
    $measurement_client = get_post($measurement_client_id);
    $measurement_client_email_addresses = get_field('field_5e14527c1945b', $measurement_client_id);
    
    $measurement_client_id = intval($_POST['acf']['field_5e147914518a6']);
    $measurement_client = get_post($measurement_client_id);
    $measurement_client_email_addresses = get_field('field_5e14527c1945b', $measurement_client->ID);
    
    $measurement_client_id = intval($_POST['acf']['field_5e147914518a6']);
    $measurement_client = get_post($measurement_client_id);
    $measurement_client_email_addresses = get_field('company_email_addresses', $measurement_client_id);
    

    The CLIENT field is an Post Object field within the Measurement group and I want to mail the measurement report to the clients emailaddress (a repeater field within the Client group).

    My logic in above code examples is as follows:
    – I know the Client (Post Object field within the Measurement post)
    – I now know the Client Post ID
    – So I could get the email address repeater field within the Client post right?

    No luck. Am I missing something here?

    Tnx John

  • I am not really sure, you’re description is confusing me a bit.

    If you are getting a sub field of a group field in $_POST then you would use

    
    $_POST['acf']['field_XXXXXX']['field_YYYYYYY']
    

    where field_XXXXXXX is the group field and field_YYYYYYY is the sub field.

    For the repeater, you need to loop over the repeater the same way you would loop over it anywhere else, or loop over the array that is returned when you use get_field().

  • My English is not to bad but when I have to express myself technically it sometimes gets a little bit off. Let me try to make it clearer by explaining my situation.

    I have a group: CLIENT
    – Name field (Post title)
    – Address field (text)
    – Phone field (number)
    – Email addresses field (repeater)

    I have a group: MEASUREMENT
    – Client field (Post object from CLIENT group)
    – Measurement field (number)
    – Some other unimportant fields

    When I add a measurement post (and within that post I have selected the Client via the Post Object field) I want to be able to mail the measurement details to the email addresses from the Clients ‘Email addresses field (repeater)’ but that field is NOT in this Group but in the CLIENT group.

    I know how to get sub field values from a repeater field in the SAME GROUP but I don’t know how to get sub field values from a repeater field in ANOTHER GROUP (via a Post Object field) using $_POST[‘acf’].

    With get_field I know I can get the values like this:
    get_field('company_email_addresses', $measurement_client->ID);

    But how does this work with $_POST[‘acf’]?

  • Just to be clear…

    I know how to get all these values within a template file, simply because there I can use it like this:

    
            $measurement_client_object					        	= get_field_object('measurement_client');
            $measurement_client						    	        = get_field('measurement_client');
            $measurement_client_name                    	    	= get_the_title($measurement_client->ID);
            $measurement_client_street_and_number	               	= get_field('company_street_and_number', $measurement_client->ID);
            $measurement_client_postal_code			               	= get_field('company_postal_code', $measurement_client->ID);
            $measurement_client_city				              	= get_field('company_city', $measurement_client->ID);
            $measurement_client_phone_number		              	= get_field('company_phone_number', $measurement_client->ID);
            $measurement_client_website				             	= get_field('company_website', $measurement_client->ID);
            $measurement_client_email_addresses                     = get_field('company_email_addresses', $measurement_client->ID);
            $measurement_client_contacts			    	        = get_field('company_contacts', $measurement_client->ID);
            $measurement_client_locations			    	        = get_field('company_locations', $measurement_client->ID);
            $measurement_client_internal_note		    	        = get_field('company_internal_note', $measurement_client->ID);
    

    But within my function.php I can’t get the values like that and I believe I have to use $_POST[β€˜acf’].

    I call the code to send out WP emails.

    Here’s my code (option ‘basic’ is not working yet, option ‘extra’ does work, option ‘all’ is easily created when I have option ‘basic’ working):

    
    // Get submitted values.
    $values				= $_POST['acf'];
    $measurement_status	= $_POST['acf']['field_5e1475a714c93'];
    $measurement_mail	= $_POST['acf']['field_5f71d9ee8536c'];
    
    if ( $measurement_status == 'completed' && $measurement_mail ) {
    
        $measurement_mail_report_recipients = $_POST['acf']['field_5f6d7d925b2fc'];
    
        if ( $measurement_mail_report_recipients == 'basic' ) {
    
            $measurement_client_id					= intval($_POST['acf']['field_5e147914518a6']);
            $measurement_client						= $_POST['acf']['field_5e147914518a6'];
            $measurement_client_email_addresses		= $_POST['acf']['field_5e14527c1945b']->$measurement_client->$measurement_client_id;
    
            if ( $measurement_client_email_addresses ) {
                $list = array();
                foreach( $measurement_client_email_addresses as $measurement_client_email_address ) {
                    $list[] = $measurement_client_email_address['field_5e1452c41945c'];
                }
                $to = implode(',', $list);
            }
    
        } elseif ( $measurement_mail_report_recipients == 'extra' ) {
    
            $measurement_mail_extra_recipients = $_POST['acf']['field_5f71d4eaaf381'];
    
            if ( $measurement_mail_extra_recipients ) {
                $list = array();
                foreach( $measurement_mail_extra_recipients as $measurement_mail_extra_recipient ) {
                    $list[] = $measurement_mail_extra_recipient['field_5f71d55aaf382'];
                }
                $to = implode(',', $list);
            }
    
        } elseif ( $measurement_mail_report_recipients == 'all' ) {
    
            $to = 'dennisdallau@hotmail.com';
    
        }
    
        // Get subject, message and header for mail and send
    
    }
    

    Within option ‘basic’ I want to retrieve email addresses from the CLIENT group and I don’t know how because these values are within another group πŸ™

  • You indicate by your code that you are working with $_POST[‘acf’] when a measurement is added.

    
    // get the client id
    $measurement_client_id = intval($_POST['acf']['field_5e147914518a6']);
    
    // get values from the client post
    // a field
    $some_value = get_field('some_field', $measurement_client_id);
    // a repeater
    if (have_rows('some_field', $measurement_client_id)) {
      while (have_rows('some_field', $measurement_client_id)) {
        the_row();
        $some_other_value = get_sub_field('some_sub_field');
      }
    }
    
Viewing 7 posts - 1 through 7 (of 7 total)

You must be logged in to reply to this topic.

We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.