Problem: I would like to use a cred_save_data hook to modify a post's author to be the current User.
Solution:
Add the current User's ID to the post's 'post_author' argument:
add_action('cred_save_data_34', 'duplicate_post', 10, 2); function duplicate_post($post_id, $form_data) { // get data of original post $post = get_post( $form_data['container_id'], ARRAY_A ); // update the new post with this data $post['ID'] = $post_id; $post['post_title'] = 'Copy of ' . $post['post_title']; // -- add this line to modify the post author -- $post['post_author'] = get_current_user_id(); wp_update_post( $post ); }
Relevant Documentation:
https://toolset.com/documentation/programmer-reference/cred-api/#cred_save_data
https://codex.wordpress.org/Function_Reference/wp_update_post
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 |
---|---|---|---|---|---|---|
8:00 – 12:00 | 8:00 – 12:00 | 8:00 – 12:00 | 8:00 – 12:00 | 8:00 – 12:00 | - | - |
13:00 – 17:00 | 13:00 – 17:00 | 13:00 – 17:00 | 13:00 – 17:00 | 13:00 – 17:00 | - | - |
Supporter timezone: America/New_York (GMT-04:00)
Dieses Thema enthält 2 Antworten, hat 2 Stimmen.
Zuletzt aktualisiert von vor 6 Jahren, 10 Monaten.
Assistiert von: Christian Cox.