Skip Navigation

[Resolved] PHP get the parent id

This support ticket is created 2 years, 7 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
- 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 -
- 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 14:00 – 18:00 13:00 – 18:00 -

Supporter timezone: America/Jamaica (GMT-05:00)

This topic contains 8 replies, has 2 voices.

Last updated by kelvinL-2 2 years, 7 months ago.

Assisted by: Shane.

Author
Posts
#2165577

Dear Sir/Madam,

I have a form containing parent and child relationships, below is the field I link to the parent

<div class="form-group parent">
	<label for="%%FORM_ID%%_@application-contestant.parent"></label>
	[cred_field field='@application-contestant.parent' class='form-control' output='bootstrap' select_text='--- not set ---' required='true']
</div>

How I get the parent id when saving the form data, I want to rename the post title as Application XXX ( YYYY ) while XXX is the parent post id and YYY is current post id.

function my_save_data_action($post_id, $form_data)
{
if ( $form_data['id'] == 2571 ) {
        $parent_id = ???????;
        wp_update_post( array(
        'ID' => $post_id,
        'post_name' => $post_id,
        'post_title' => sprintf("%s - %s (%s)", 'Application', $parent_id, $post_id)
        ));
    }
}
add_action('cred_save_data', 'my_save_data_action',10,2);
#2165725

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Kelvin,

To get the Parent ID from the form you can try doing this.

$_POST["application-contestant_parent"]

If that doesn't work try this one below.

$_POST["application-contestant-parent"]

Thanks,
Shane

#2165739

Sorry both not work

#2165741

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Kelvin,

Would you mind providing me with a link to the page where the form is so that I can check the payload of the Post request to get the correct field name.

Thanks,
Shane

#2165757

You have to login with specific role

As this is not private message, could you remove this after testing?

#2165775

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Kelvin,

You're setting the parent based on a parameter in the URL correct.

If so then you can simply do this.

$_GET["parent_vwcm-application_id"]

This will get the parent ID for you from the URL.

Thanks,
Shane

#2165777
#2165811

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Kelvin,

Great happy you were able to find a solution on our forums.

If there are no further queries then you can go ahead and mark this ticket as resolved.

Thanks,
Shane

#2166613

My issue is resolved now. Thank you!

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.