Skip Navigation

[Resolved] field group title in php

This support ticket is created 4 years, 8 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Kolkata (GMT+05:30)

This topic contains 2 replies, has 2 voices.

Last updated by BrandenT2154 4 years, 8 months ago.

Assisted by: Minesh.

Author
Posts
#1595073

I have a repeatable field group for contacts.

the first field is contact name

I wish to programmatically update the 'field group title' to equal the contact name upon post save.

I see this method here: https://toolset.com/documentation/customizing-sites-using-php/updating-types-fields-using-php/ but i am unable to find how i can refer to the field group title of a particular field group in a repeating field group.

is there a method for this?

#1595451

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

You can use the post-relationship API function toolset_get_related_posts() to grab the related repeating field group item IDs.

Can you please try to add the following code to your current theme's functions.php file:
Or
The toolset also offers a place to add the "Custom Code":
=> https://toolset.com/documentation/adding-custom-code/using-toolset-to-add-custom-code/

add_action( 'save_post', 'func_update_rfg_titles', 99, 2 );
function func_update_rfg_titles( $post_id, $post ){
    if ( 'tour' == $post->post_type ) {
 
           $child_ids = toolset_get_related_posts(
                                     $post_id,
                                     'tour-guide-contact',  // replace with your repeating field group slug
                                      'parent',
                                      999,
                                       0,
                                       array(),
                                      'post_id',
                                      'child'
                                      );
 
 if (!empty($child_ids) ){
      
    foreach ( $child_ids as $child_id){
		
	 remove_action( 'save_post', 'func_update_rfg_titles', 99, 2 );

        $title = get_post_meta($child_id,'wpcf-contact-name',true);
        
		$title_update_args = array(
			'ID'           => $child_id,
			'post_title'   => $title
		);
		wp_update_post( $title_update_args );
		add_action( 'save_post', 'func_update_rfg_titles', 99, 2 );
     }
    
}
  }
}

Where:
- Replace tour with your post type
- Replace "tour-guide-contact" with your original repeating field group name
- Replace slug wpcf-contact-name with your original Contact Name field slug if required

More info;
=> https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/#toolset_get_related_posts

Please let me know if you require further assistance with the above code.

#1600929

wow thank you so much! works perfectly, thank you so much for such an easy fix