On a WordPress site I have authors who can submit content and editors who can evaluate and comment on it. Submitted content uses it’s own post type and evaluation is done showing a ACF 5 form with text and star rating fields.
My problem is a conceptual one, namely where to save evaluation data to:
So I would need to save the evaluations neither to submitted content (post_1, post_2, …) nor to evaluators (user_1, user_2, …) but to a unique post and user combination (evaluation_1_1, evaluation_1_2, …):
How is the common way to do so? Do I have to create a new content type “evaluation” with references to submitted content and to evaluating editor and make queries on each evaluation to know if content already has been evaluated?
Or is there an easier way to go? I think of something like a custom $post_id:
'post_id' => "post_".$post_id."_".$uid,
Maybe real simply thought, but why not store the data in post_meta in an array ? Then it can hold several evaluations. It doesn’t have to be a single value.
Thanks for your thought. Can ACF store data in post_meta or would I have to do that directly with WordPress API?
Could you outline the steps to follow? I have some programming experiences but know little about ACF and WordPress API.
Edit: if the field is an ACF field, then you can. Then you can use update_field like this update_field($selector, $value, $post_id);
You can save it like any other value except now you save an array.
$your_array = array( 'some value', 'other value' );
update_post_meta( $post_id, $meta_key, $your_array );
update_field( $meta_key, $your_array, $post_id );
Thanks for your hint, saving evaluation data as array solved my issue.
I implemented this using a standard ACF form group loaded from the single.php template and adding the following hooks:
$value = get_post_meta( $post_id, $field['name']);
$value[get_current_user_id()] = $value;
$value = get_post_meta( get_the_ID(), $field['name']);
$field['value'] = $value[0][get_current_user_id()];
The topic ‘How to save ACF data to a unique post and user combination’ is closed to new replies.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.