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,
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[get_current_user_id()];
You must be logged in to reply to this topic.
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!
© 2022 Advanced Custom Fields.