Default value for ACF taxonomy field
-
Will this plug in enable me to set the default value of a taxonomy field when a NEW post is being created? If not, can anyone point me to where I might find the appropriate PHP code?
-
Hello,
Thanks for the feedback!
You can set the “Default Value” setting using a Term ID in the Taxonomy Terms field added by ACF Extended. This field is an advanced version of the native ACF taxonomy field.
If you want to programmatically set a default value to any field, you can use the
acf/load_field
hook. See documentation.Hope it helps!
Regards.
Re the “item status” custom field: I have changed the existing field type from “Taxonomy” to “Taxonomy terms” and specified the default value as “New item”. However, when I add a new “item” (a custom post type) a different taxonomy term appears. (The one that appears is the term at the top of the list.) I have also tried it using the term ID.
Hello,
Thanks for the feedback. I’m not sure to understand what you mean by:
The taxonomy field type contains 3500 rows of data
Do you mean that you have 3500 meta saved in posts, with that field type?
You can simply change the field type from the ACF “Taxonomy” to the ACF Extended “Taxonomy Terms” type in your field group, the meta data are compatible.
Hope it helps!
Regards.
You are too fast. I edited the original post.
Hello,
Thanks for the feedback! You have to use the Term ID (a number), not the “Term Name” or any other value in the “Default Value” setting of the Taxonomy Terms field.
To find the ID of your Term, go in the admin, edit a Term/Category, and check the URL. It should be:
/wp-admin/term.php?taxonomy=category&tag_ID=22
In that URL, you’ll find the Term ID in
tag_ID=22
. Here, it is22
.Here is a demo of a Taxonomy Terms field using
22
as default value (for the term named “Category 3”), and correctly working when adding a new post:- Screenshot: Default Value set to 22
- Screenshot: Add New post with Category 3 used as default
- Screenshot: Categories List admin
Related article: How to find the WordPress category ID in your WordPress dashboard.
If it still doesn’t work, please provide a full screenshot of your ACF Taxonomy Terms Settings UI (including the Default Value setting), an example of the Term Edit URL and a screenshot of your “Add new post” screen.
Note: Please avoid editing a question if you had the correct answer to update it with an another question, as it break the topic readability. Previously answered question could also help someone else. Instead, post a new question.
Hope it helps,
Regards.
I can’t get a screen shot of the Taxonomy Terms Settings UI (including the Default Value setting) because it pans at least two screen heights and I don’t see how to attach files to this reply. This is strange because the default values of two other fields works properly but the default value for “item status” does not.
I can send you a temporary login link if that would help?
Hello,
You can send screenshots using a website like https://imgur.com/, which let you upload images and give you an URL to share.
Just like I did in my last answer where I shared screenshots, haven’t you seen them?
– Screenshot: Default Value set to 22
– Screenshot: Add New post with Category 3 used as default
– Screenshot: Categories List adminRegards.
Here are the links:
Hello,
Thanks for the screenshorts. Can you please share the complete screenshot of
item-status
UI from the ACF admin? I would like to check other settings of the field.Are you sure you’re on a “Add New Post” page (a new post that has never been saved before).
Also, are you using the “Load Terms” setting in the
item-status
field configuration?Regards.
OK got everything to work. I had identified the default values for each taxonomy in CPT UI and, when I removed these, the default values are now appearing correctly on the “Add new” screen.
- The topic ‘Default value for ACF taxonomy field’ is closed to new replies.