Home › Forums › General Issues › Automatically register a field group when adding a category › Reply To: Automatically register a field group when adding a category
This is an old topic and you’ve probably moved on but for anyone that’s looking for the same type of thing.
The first thing I ask is what will having a different field group for each category give that that having the same field group on all categories won’t.
If you still want to do this, you would not create a new field group every time a new category is created, you would create some custom php code that would run and create a field group and fields for each category that exists.
I’d start by exporting a field group that’s attached to a specific category first and use this for an example. Then I would add an function that runs on WP init
add_action('init', 'add_category_field_groups');
function add_category_field_groups() {
// use get_terms to get a list of categories
// https://developer.wordpress.org/reference/functions/get_terms/
// loop through the categories and create a field group
// I would set the group key to something like
// "group_termid000{$term->term_id}"
// see https://www.advancedcustomfields.com/resources/register-fields-via-php/
}
Hope that helps someone
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.