Oops, the URL I wrote above linked to 404. I fixed it to redirect properly.
In my last post, I didn’t explain my solution well enough. I referenced the code of acf-ninja-forms (https://github.com/bostondv/acf-ninja-forms). It uses prepare_field to use the native select field and I followed it.
In my case, add_action is called on __construct (like the post_object field) and append ‘ajax_action’ to $field on prepare_field. While this approach has worked for me, it may be unusual because it doesn’t use the ‘input.js’ of the plugin itself.
I’m going to leave the code unchanged but I’d like to know more about your solution. Could you show me (or us, include future viewers) your sample code or repository?
Thank you for your reply, tgillet1. I had forgotten this post until I received a notification email. In fact, I already solved this issue myself and realized I misunderstood about the field.
As you said, the field box with a number-field-like appearance was just a multi-select field with size=”1″. I jumped to the wrong conclusion.
By the way, I’d like to write down my findings here for future reference.
[1] Of the above code, $field[‘ajax’] = 1 was not necessary. On the contrary, it causes blank field when used with $field[‘ui’] = 1 (unless ajax actions are properly set).
[2] Even when $field[‘ui’] is set to 1, the appearance of the field still not be ‘Stylized UI’. For example, here is the code and rendered field images.
function render_field( $field ) {
$field['type'] = 'select';
$field['ui'] = 1; // or 0
$field['multiple'] = 1; // or 0
$field['choices'] = array(
101 => 'Choice-1',
102 => 'Choice-2',
103 => 'Choice-3',
);
acf_render_field( $field );
}
Since I couldn’t solve this problem, I took an alternative approach.
[3] Referring to other ACF plugins, I solved the issue by using the prepare_field function instead of the render_field function. Here is the URL of the plugin I created.
https://github.com/game-ryo/ACF-Multiple-Taxonomy-Field
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.