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?
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