Just want to say, maybe will better to add some explanation on the ACF Group documentation page. “You can use get_gield() in [this way] for sub-fields etc”.
@chriskirknielsen Thanks! It works.
More details for next people:
1) https://stackoverflow.com/questions/30074492/what-is-the-difference-between-utf8mb4-and-utf8-charsets-in-mysql
2) https://make.wordpress.org/core/2015/04/02/the-utf8mb4-upgrade/
3) https://wordpress.stackexchange.com/questions/266805/please-explain-how-wordpress-works-with-mysql-character-set-and-collation-at-a-l
4) https://gist.github.com/carlalexander/4106cfaaf405cec454ba195631bcb6bc
Yes, I tried and it works. But is it an ACF feature or temporary luck? I mean if I will use this method could I think that ACF going to work that way long time in the future?
$group_subfield_in_any_times_on_future = get_field($group_name . '_' . $subfield_name);
Or does it fraught with problems in the future (some breaking changes)?
One year passed and we still are here… I can’t use $field[‘disabled’] = true; for ‘true/false’-field, because that doesn’t work. It’s a bit strange to have the functional which don’t work with two type of field. Why that is?
“Are you seeing the problem with the stylized UI on or off?” – Yes.
If I make the field[‘ui’] = 0; then will $field[‘disabled’] = true work? Where I need do it? I mean now I work into ‘acf/prepare_field’.
I see. With comments “// do something here”, the code looks better. It is clear that this is optional.
At final I reject acf_form() because I don’t know how can I use it with hidden fields.
I think ACF need the setting “Hidden in front-end: true/false” and the parameter acf_form() “input_init_values” => $init_values.
For example, how must I do with acf_form():
Question post about some item:
1) item_id (hidden for user in front-end)
2) title
3) message
Without acf_form() it will be:
<form action="<?php echo get_stylesheet_directory_uri() ?>/question-update.php" method="POST">
<input type="hidden" name="item_id" value="<?php echo get_the_ID() ?>" />
<input type="text" name="title" value="" />
<input type="textarea" name="message" value="" />
</form>
At first:
I must use keys, like “field_5729dc2c38f13”, instead names of fields.
The solution for hidden in acf_form() fields (By “hidden” I mean that I don’t show it the field to user in front-end):
update_field('_status', $status_term_obj->term_id, $post_id); // don't work
update_field('field_5729dc2c38f13', $status_term_obj->term_id, $post_id); // work!
I hope that will help someone.
“In the name of The Old Gods and the New” (с) 🙂
Yes! It’s working! Thanks, John.
I must use keys, like “field_5729dc2c38f13”, instead names of fields.
The solution for hidden in acf_form() fields (By “hidden” I mean that I don’t show it the field to user in front-end):
update_field('_status', $status_term_obj->term_id, $post_id); // don't work
update_field('field_5729dc2c38f13', $status_term_obj->term_id, $post_id); // work!
I hope that will help someone.
Yes, it’s the full answer. Thanks.
After some experiment, I understand where is the true problem. $value is correct, but something wrong with updating process:
Time is going… So, at first, this is for User Object.
If you will use get_field() you will get OBJECT, but if you will set update_field() you must put ID or ARRAY_OF_ID (for multiselect field). It isn’t clear for using and I didn’t see an ACF tutorial for it.
Will be great have a fine tutorial in Documentation “How to use update_field() for complex objects like User, Taxonomy, etc”. Because in wp-admin you just click mouse & select, but in code you must use correct format $value.
At second, the question about “update_field() with field_taxonomy” is open.
So… The Support replied: “…you will need to pass the $term object to the $value parameter of the function”. Ok. Lat’s do it now!
Inside “acf/save_post”:
$current_user = wp_get_current_user();
update_field('_user', $current_user, $post_id); // user_obj, but don't work, why is it?
update_field('_user', $current_user->ID, $post_id); // just ID, but works fine
$status_term_obj = get_term_by('slug', 'created', 'request_status'); // it's term_obj
update_field('_status', $status_term_obj, $post_id); // don't work!
In Debuger update_field() looks:
http://prntscr.com/b0hup1
The Tax_Term_Obj there is, but the Field_Obj is “null”. Why?
Here is this field: http://prntscr.com/b0hzo4 and that field_group is added to post_type=”request”.
Maybe it’s important: fields “_user” and “_status” in fields_group “Request Admin Part” and they don’t show in acf_form() and set in code “acf/save_post”.
Thanks, John!
In future, I going to use ACF 5 Pro.
First. Thanks for help with instructions!
Second. Yes, I was thinking about something like that. For minimizing surprises in future it’s better way:
add_filter('acf/update_value/name=titles', 'wp_slash', 1);
But it’s a typical crutch (not sure is it good English word).
Thirdly. Can you tell me clear why ACF do unshielded my strings at that place? Looks like ACF do the “bad” action there. And why put a comment with a link (I think there is the problem description, but now it’s broken). I want to understand why we need this string in ACF-code:
$value = stripslashes_deep($value);
I came back! 🙂
Now I’m just one step away to the solution. So… What have we?
I wrote into the field, for example, “\0”. I pressed “Save post”. And in Debugger, I saw the string $v=”\\0″ in PHPStorm. So, some code makes my string shielded from “\0” to “\\0”. It’s good because without that we will have controls symbol.
But later in this place:
[domen]\wp-content\plugins\advanced-custom-fields\core\fields\_functions.php
on the 181 row the function update_value( $value, $post_id, $field ) un-shielded my string: $value = stripslashes_deep($value);
Screenshot: http://prntscr.com/ao66r9
I see comments about “not need” etc, but I don’t understand this very clear. Especially in regard to the possible impact on other fields. And why need we strip slashes?
Easy solution looks like: //$value = stripslashes_deep($value); But I concern about effect on other fields.
Please, help me comprehend this all. I think this will be helpful for other people.
Ok. Thanks.
I will write here the solution of the problem in future.
Hmm… It’s not good news.
Maybe you can advise me? Look at please: http://prntscr.com/ao2ahp
I think I didn’t some special actions with the character set. I’m confused.
Do I understand you right? It’s not ACF-plugin. Maybe it’s WP-core?
Just advise me, please: the right direction for Google search or any tries to fix it.
P.S. Sorry about my English. 🙂
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.