Home › Forums › ACF PRO › Display List of category from multisite in theme option › Reply To: Display List of category from multisite in theme option
See https://www.advancedcustomfields.com/resources/dynamically-populate-a-select-fields-choices/
function acf_load_categor_field_choices( $field ) {
$args = array('public' => true);
$sites = wp_get_sites($args);
foreach ($sites as $site) {
switch_to_blog($blog_id);
$categories = get_categories();
foreach ($categories as $category) {
// I'm using both the blog id and the term id for the
// select value so that you'll know what site to get
// the category from
field['choices'][$site['blog_id].'-'.$category->term_id] = $category->term_name;
} // end foreach category
restore_current_blog();
} // end foreach site
return $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.