Skip Navigation

[Resolved] Copy content of a custom field to default post author field

This support ticket is created 4 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
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)

This topic contains 2 replies, has 2 voices.

Last updated by signisF 4 years, 7 months ago.

Assisted by: Christian Cox.

Author
Posts
#1630607
Captura de ecrã 2020-05-19, às 15.49.18.jpg

I want to copy custom field content of all posts to default post author field. How can i do that?

#1631245

Hello, the simple answer is it's quite complicated and there's nothing built-in to Toolset that will help you achieve this. Even with custom code, it's quite difficult. When you want to set the post author programmatically, you need to know the author's WordPress User ID. This is how post authorship is managed in the database - a User ID is stored in the post table. It looks like the Autor Musica custom field does not include the author's User ID, but includes some other information instead. This complicates things because you need a way to translate from this information to the WordPress User ID. I'm not sure how that would be possible. You could look into the wordpress WP_User_Query class: https://developer.wordpress.org/reference/classes/wp_user_query/
You can search by several criteria like 'ID', 'user_login', 'user_email', 'user_url', 'user_nicename', 'display_name', as well as custom field values on the User Profile. However, I'm not sure what information your Autor Musica field contains. My guess is the information here is not easily translatable into author ID, am I correct?

#1631769

My issue is resolved now. Thank you!