![]() |
Hi all,
I have two post types: one called people and another called responses. The responses post type holds survey resources, that are linked back via and ACF relationship field to the associated person who was selected when submitting the response form. This meta field in the responses post type is sourcepost. The return type of the field as set in ACF is the post ID.
What I'm looking to do is copy some meta values over from the response to the associate person record. For example, when responding the user can upload a headshot -- so I'd like to set that as the thumbnail. Additionally there is a field to set the "didrespond" status to "Yes".
(Survey responses need to be manually verified before going live, hence the need of separating the persons "profile" from their responses to begin with.)
Here's what I have, which seems like it would be right from what I've read about transition_post_status, but nothing appears to be copying over. I'm assuming it has something to do with the post object. Survey responses initially are saved as drafts. When someone comes and verifies the response and switches to published is when I'd like to copy the meta values over to the associated post.
I found this Gutenberg issue (https://github.com/WordPress/gutenberg/issues/12897) which is maybe related(?), but I have Gutenberg disabled for these two post types at least so I'm not totally sure.
Is there another way to accomplish this or am i just missing something below?
Solution - 1Do you have staging site? Solution - 2Hi Andrew, If you want to copy or update values from "responses" post type to "people" when the new response published you will use this code
Solution - 3You can try. post_updated https://developer.wordpress.org/reference/hooks/post_updated/ or save_post https://developer.wordpress.org/reference/hooks/save_post/ or save_post_{$post_type} https://developer.wordpress.org/reference/hooks/save_post_post-post_type/ Solution - 4Your code looks great, just add a validation for when there is no featured image, you could try debugging the received data, confirm the name of your post type and custom fields. just to confirm that you take correct data
Solution - 5Could you explain more Solution - 6what exactly do you require |
Wordpress |
Type: | Code Example |
Category: | Coding |
Sub Category: | Code Example |
Uploaded by: | Admin |
Views: | 30 |