Skip Navigation

[Resolved] Can you have all CPT submitted through a front-end form be assigned to admin?

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.

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.

This topic contains 2 replies, has 2 voices.

Last updated by Ronald 4 years, 8 months ago.

Author
Posts
#1541525

I want to create a front-end form for 2-3 workers to go in and bulk add my "resource" CPT. But I want all of those added through this specific form to have my administrator account set as the author. I am not seeing a setting when I create a new post form to set an author, is this a possibility?

#1541689

The best way to go here would be to use a small custom snippet, which uses wp_update_post() and updates the post author, in a cred_save_data hook.

1. The cred_save_data() hook is a function that allows you to add custom code to the moment when Forms saves a post in the database.
https://toolset.com/documentation/programmer-reference/cred-api/#cred_save_data
2. wp_update_post() is a WordPress method to update a post.
https://developer.wordpress.org/reference/functions/wp_update_post/

Such function, to update the post author when a form submits, could look like this:

add_action('cred_save_data', 'my_save_data_action',10,2);
function my_save_data_action($post_id, $form_data)
{
    // if a specific form
    if ($form_data['id']==12)//Change your form ID
    {
        $user_id = '1';//Change this to your own admin user id, usually, it is 1
        $my_post = array(
            'ID'           => $post_id,
            'post_author' => $user_id,
        );
        wp_update_post( $my_post );
    }
}

Please study the above-linked DOCs for understanding the methods used, which will be required to maintain and expand above code, if required.

Thanks!

#1542233

Thanks! I think this is exactly what I need. I should be able to get a final product from it.