Skip Navigation

[Resolved] Create a post and then connect the relationship to the parent

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.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9: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/Hong_Kong (GMT+08:00)

This topic contains 2 replies, has 2 voices.

Last updated by Mario 4 years, 8 months ago.

Assisted by: Luo Yang.

Author
Posts
#1323821

Tell us what you are trying to do?

Create a post and then connect the relationship to the parent. (one to many)

The problem I am encountering:
I have created a function that creates the post and connection.

How do I obtain the parent and child post id's for the relationship connection.

The parent is the current logged in user and creator of the post.
The new form post is the child.

=======


/** Create new Hire-Proposal */
add_action('cred_save_data', 'my_save_data_action',10,2);
function my_save_data_action($post_id, $form_data)
{
    if ($form_data['id']==1111)
    {
$my_post = array(
	'post_title' => $_POST['post_title'],
    'meta_input' => array(
    'wpcf-cp-mem-id' => $post_id.$user_ID,

	'wpcf-cp-mem-id-ref'  => 'LC'. $post_id.$user_ID . 'CP2',

    'wpcf-first-name1' => $_POST['first-name1'],
    'wpcf-last-name1' => $_POST['last-name1'],
    'wpcf-service-address' => $_POST['service-address'],
    'wpcf-service-postcode' => $_POST['service-postcode']
    ),   
	'post_content'  => 'xx',
    'post_status'   => 'publish',
    'post_author'   => $post_id,
    'post_type' => 'csh-proposal-to-hire'
);
    
wp_insert_post( $my_post );

>>>>>>  $parent_author_id = get_post_field ('post_author', $parent_post_id);
>>>>>>  $child_ph_id = post_id;

   toolset_connect_posts( 'seeker-proposal-to-hire-link', $parent_author_id, $child_ph_id )

    }
}

#1324035

Hello,

Since it is a custom PHP codes problem, please elaborate the question with more details:
1) How do you setup the post form?
2) How do you setup the custom field "post_author"?
3) How do you setup the relationship "seeker-proposal-to-hire-link"?

#1324667

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.