Skip Navigation

[Resolved] CPT created by function finding the the post for the view

This thread is resolved. Here is a description of the problem and solution.

Problem:
Post created using Toolset user form using wp_insert_post- how to assign the post author

Solution:

You can find the proposed solution in this case with the following reply:
https://toolset.com/forums/topic/cpt-created-by-function-finding-the-the-post-for-the-view/#post-1263671

Relevant Documentation:

This support ticket is created 5 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
- 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 Mario 5 years, 7 months ago.

Assisted by: Minesh.

Author
Posts
#1263543

Tell us what you are trying to do?

The code below creates a CPT when a user is created.
the form cred then redirects to another page.

I'm struggling to find a way to find the CPT just created.

I have created a view and tried these ways to find the CPT.
--
'Post author is the same as the logged in user'
and
'Select posts with the author the same as the current post in the loop.'
and
I have also tried passing the post id in cred submit using urlparam.

[cred_field field='form_submit' output='bootstrap' value=' Next > ' url_param="wpv-cp-mem-id" class='btn btn-danger btn-lg']

not sure how to call call the post

-----

add_action('cred_save_data', 'my_save_data_action',10,2);
function my_save_data_action($post_id, $form_data)
{
if ($form_data['id']==2368)
{
$my_post = array(
'post_title' => $_POST['first_name'] . ' ' . $_POST['last_name'] . ' ' . $post_id,
'meta_input' => array(
'wpcf-cp-mem-id' => $post_id,
'wpcf-cp-first-name' => $_POST['first_name'],
'wpcf-cp-last-name' => $_POST['last_name']
),
'post_content' => 'xx',
'post_status' => 'publish',
'post_author' => $user_ID,
'post_type' => 'cp-provider'
);

wp_insert_post( $my_post );
}
}

#1263671

Minesh
Supporter

Languages: English (English )

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

Hello. Thank you for contacting the Toolset support.

Well - as I understand, you have Toolset user form with ID 2368 and you want to assign the post author with newly created user ID.

To assign the newly created user ID - you should try to use the following:

'post_author' => $post_id,

Where:
$post_id is actually a user ID.

#1264725

My issue is resolved now. Thank you!