Navigation überspringen

[Gelöst] Assign a custom field to the postype created by Cred

This support ticket is created vor 5 Jahren, 9 Monaten. 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)

Dieses Thema enthält 2 Antworten, hat 2 Stimmen.

Zuletzt aktualisiert von Pat vor 5 Jahren, 9 Monaten.

Assistiert von: Minesh.

Author
Artikel
#1238628

Pat

Hello,

I have a Cred that is used to create messages.
No issue at that time.
Now, I need to change the created post author and replace it by a field managed in the Cred (visitor_id)
How can I do this?

Regards
Pat

#1238645

Minesh
Supporter

Sprachen: Englisch (English )

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

Hello. Thank you for contacting the Toolset support.

Well - you should use the Toolset form's hook "cred_save_data" to update the post author for created post.

For example:
- Please try to add following code to your current theme's functionns.php file
OR
- Custom code section offered by Toolset:
=> https://toolset.com/documentation/adding-custom-code/using-toolset-to-add-custom-code/

add_action('cred_save_data', 'func_update_post_author',30,2);
function func_update_post_author($post_id, $form_data){
    
   if ($form_data['id']==9999){
        
            $post_args = array(
            'ID'    => $post_id,
            'post_author'   => 7777, // replace with your visitor_id variable $_POST['visitor_id'] or  $_POST['wpcf-visitor_id']
            
        );
        // update post author
        wp_update_post( $post_args );
    }
}

Where
- replace 9999 with original form ID

More info:
=> https://toolset.com/documentation/programmer-reference/cred-api/#cred_save_data

#1238951

Pat

Hi Minesh,

Many thanks for your support.
Regards
Pat