Correcting code written by Chat GPT for displaying actual author of the post.
-
Under the USERS i have created 8 users. When one of those 8 users are loged in, they can write new post and publish it, and before they publish it they can select from the author dropdown list any nickname, but that doesn’t mean that user with that nickname wrote that post.
For example user X can select user Y from the dropdown list.
So in my case i have a lot of users who are selecting the same nickname from the dropdown list, because that nickname represents the global shared name of the company.
But then I don’t know who of those 8 users actually wrote that post.So I want to display the name of the actual user who wrote the post, regardless of the author nickname selected during post creation.
I want to create new column in the post section and in that column I want to display that real user .
In that column I would like user to be displayed?by the NAME column in the “users” section…I asked Chat GPT to write me that code and he provided me this one that actually creates new column with the “Actual Author” label but unfortunately it doesn’t work as it should.
So maybe there’s just some little thing to correct or maybe the whole code isn’t correct. I don’t know cause I really don’t know how to code so maybe some of you could help me with this one.
I would be really greatful
I tried to tell GPT to redifine the code several times but none of them works :/This is one of the codes it provides me:
// Add custom column function custom_posts_columns($columns) { $columns['actual_post_author'] = 'Actual Author'; return $columns; } add_filter('manage_posts_columns', 'custom_posts_columns'); // Populate custom column with actual author information function custom_posts_custom_column($column, $post_id) { if ($column === 'actual_post_author') { $post = get_post($post_id); $author_id = $post->post_author; $author = get_userdata($author_id); $actual_author_id = $author->ID; // Actual user's ID $actual_author_name = get_user_meta($actual_author_id, 'first_name', true) . ' ' . get_user_meta($actual_author_id, 'last_name', true); // Actual user's name echo $actual_author_name; } } add_action('manage_posts_custom_column', 'custom_posts_custom_column', 10, 2);
- The topic ‘Correcting code written by Chat GPT for displaying actual author of the post.’ is closed to new replies.