Problem:
The issue here is that the user wanted to change the author of the posts from the frontend.
Solution:
This is possible to do if you've created a generic form field that you've populated with the Name and ID of the users you want to be the possible selections for authors.
To get started this will essentially be an edit form for the post with all other fields removed. Then under Generic Fields you will add a generic Select Field.
For the Labels you will add the Authors name and for the Value you will add the ID of that author. This list will need to be maintained manually with all the users on your site that will be authors. See My Screenshot
The next step is to add the form to the page and then use the code below to trigger the author update once the form is submitted.
add_action( 'cred_save_data', 'tssupp_change_author', 10, 2 ); function tssupp_change_author( $post_id, $form_data ){ if ( in_array( $form_data['id'], array( 123 ) ) && !empty($_POST['authors'])) { $post = array( 'ID' => $post_id, 'post_author' => $_POST['authors'] ); wp_update_post( $post ); } }
Now you will need to change 123 to the ID of the edit form and the 'authors' to the slug of the generic field that you had created. This code can be added to the Toolset Custom code section in Toolset -> Settings -> Custom Coding. Once you've added the code you will then need to activate it.
Once activated and the information added to the code and form is correct then you should be able to successfully change the post author.
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 |
---|---|---|---|---|---|---|
- | 9:00 – 12:00 | 9:00 – 12:00 | 9:00 – 12:00 | 9:00 – 12:00 | 9:00 – 12:00 | - |
- | 13:00 – 18:00 | 13:00 – 18:00 | 13:00 – 18:00 | 14:00 – 18:00 | 13:00 – 18:00 | - |
Supporter timezone: America/Jamaica (GMT-05:00)
This topic contains 2 replies, has 2 voices.
Last updated by 3 years, 9 months ago.
Assisted by: Shane.