Skip Navigation

[Resolved] Get the post ID for a new post created with cred form

This support ticket is created 4 years, 9 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 – 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 1 reply, has 2 voices.

Last updated by Luo Yang 4 years, 9 months ago.

Assisted by: Luo Yang.

Author
Posts
#1764623

Tell us what you are trying to do?
I am trying to get the post id for a new custom post type that is created when another post is created. I am currently doing this:

add_action('cred_before_save_data', 'add_live_stream_post',10,1);
function add_live_stream_post($form_data) {
if ( is_user_logged_in() ) {
if ($form_data['id']=='202') {
// Get current user
$current_user = get_current_user_id();

// Create post
$my_post = array(
'post_title' => $current_user,
//'post_content' => $_POST['post_content'],
'post_status' => 'publish',
'post_author' => $current_user,
'post_type' => 'live-stream'
);

// Insert the post into the database
wp_insert_post( $my_post );
}
}
}

Form 202 creates the first custom post and I need to get the post id for the 'live-stream' post_type that was just created as well as the post id that was created with form 202. What is the best way to do this? Thank you for your assistance.

Is there any documentation that you are following?
No.

Is there a similar example that we can see?
No.

What is the link to your site?

#1764795

Hello,

The action hook "cred_before_save_data" is triggered before new post created, so there won't be any post ID, see our document:
https://toolset.com/documentation/programmer-reference/cred-api/#cred_before_save_data

In your case, you can try another action hook cred_save_data, which is triggered after new post created:
https://toolset.com/documentation/programmer-reference/cred-api/#cred_save_data

And there is argument "$post_id", you can use it in your custom PHP codes, see example of above document