Hi
I have created ACF theme option page in main site. I have arround 5 multisite created. I want list of all categories from multisite to display in main site theme option.
For e.g if there are 4 categories in site 1 and 3 categories in site so on… then want to display this all categories in main site theme option and user can select any one categories from dropdown.
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;
}
Hi John,
Thanks for reply, but sorry this is not working… i think you misunderstood my question.
Basically what i want is..
I will create a field type of Taxonomy with Taxonomy as category in theme option of ACF. In default function it will show list of current categories. But instead I want to display all categories from multi-sites.
That means it will show complete list of categories available in all sites.
What I did was for a select field. I don’t think you can do this for a taxonomy field. Taxonomy fields are select2 fields populated using AJAX and the way the ACF functions work I don’t think it’s possible to get terms from other blogs in a multisite.
I’d suggest that you look at the functions in the ACF code to see how the taxonomy fields are populated. in the ACF plugin folder /fields/taxonomy.php
This person has created a multisite relationship field. https://github.com/tmconnect/acf-relationship-multisite. You might be able to use some of that and some of what’s in the taxonomy field and create you own field type.
John,
Thanks for calling attention to the ACF Relationship Multisite add-on.
Pre v5.0, we were successfully using a Multisite Taxonomy field. I can’t get it to work with 5+ though.
https://gist.github.com/electricbrick/cec719bf650e535e143f518603dd38ed
And as a heads-up to anyone who comes across this thread, the relationship multisite field add-on project is now dead.
The topic ‘Display List of category from multisite in theme option’ is closed to new replies.
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.