Use conditional check on blog_id on the php export file. That’s what I did too for a similar setup.
@pixelbart Unfortunately this isn’t working any more. update_field requires more arguments.
https://www.advancedcustomfields.com/resources/update_field/
Is there another solution to bulk save posts so the new custom field with a default value?
Can anyone please help?
That solved the issue! Thank you!
@hube2 OK, yes you’re right. I just tested it as well. I am getting the field groups just fine. I am getting them in a plugin after ACF initialized.
However, I am not getting all the fields in each field group. I am only getting the fields of the last field group in the PHP file under each field group.
I tried the same function acf_get_field_groups
but that did not work. It only works when the fields are created in the database in the ACF admin page but not when they are registered by PHP.
Thanks John. I will contact them about it. This plugin hasn’t been updated since a year now. Maybe they have not added support for it.
For now I will use this instead – a modified version of the sync json acf plugin.
https://gist.github.com/amjad/0d8bd7e9108001defc5fed546787a17b
Only major down side of this is that it creates the fields in the database for each sub site which is what we are trying to avoid for performance reasons.
Adding "private": true
just hides the fieldgroup from the Sync Available tab and does not show it in the All tab. Other code or plugins that need to access the field groups are not being able to access them.
Interesting. It might be difficult to edit multiple JSON files everytime I make changes. What about PHP export file that will just be one file so its easier to edit. What can I add to it to make them show up in ACF admin on secondary sites?
I don’t plan to edit them either on the secondary sites (I have hidden that menu).
So then what’s the difference between using JSON and PHP?
I did just that. I updated each field group on the main site where I edit the fields and I see all json files generated in the acf json folder. I went into each site and this is what I see:
There no custom fields defined in any of the other sites. They have not synced or registered with all other sites.
This is my setup:
Main site – different theme, different fields (used for admin purpose only)
All sub-sites – same theme, same fields (used by clients)
One of my sub-sites is called a “template” site where I make all pre-defined changes I want to replicate on all other sub-sites.
I am not doing anything on the main site for this. I am just using the template site where all the custom fields are created in the dashboard. I created acf-json folder in the theme folder which is shared by all other sites.
I made changes to all my field groups and I see a json file being created for each group. On all other sites, I see “Sync Available” tab in custom fields page. Is there a way to automatically sync it? That’s what I am asking.
It did not work. The json file is being generated fine, but nothing is syncing automatically. I don’t see any custom fields on all other sites except the one I am creating them on (which has the same theme as others)
One thing I forgot to mention. The main site uses a different theme (because I need different custom fields there), however all other sites use a common theme. Is that going to be a problem?
@hube2 Perfect! thank you. I will test it out now and report back here.
@hube2 Yes, all sites use the same theme. From that local json page, it seems like I have to manually sync on each site? Is there a way to automate syncing?
From my use case, I have one template site where I make all the changes to the fields, once I save any changes, I want them to be automatically synced to all sites in my network.
I have made it work. See my example code:
add_filter('acf/load_value/name=product_type', 'my_acf_load_value', 10, 3);
function my_acf_load_value( $field ) {
if (isset($_GET['product_type'])) {
$product_type = $_GET['product_type'];
$field = $product_type;
}
return $field;
}
Answering my own question above. This is how you can exclude categories based on slug. In my case, I have a multi-site and category id may change. Following example is to hide the Uncategorized category. (I’d like to keep it as the default one and not rename it for my own reasons). Hope that helps somebody in the same situation.
// get term id's
add_action( 'init', 'get_term_ids' );
function get_term_ids() {
global $uncategorized_id;
$u = get_term_by( 'slug', 'uncategorized', 'product_cat' );
$uncategorized_id = $u->term_id;
}
// exclude categories from category dropdown
add_filter('acf/fields/taxonomy/query/name=category', 'exclude_categories', 10, 2);
function exclude_categories( $args, $field ) {
global $uncategorized_id;
$args['exclude'] = array($uncategorized_id); //the IDs of the excluded terms
return $args;
}
Thanks everyone!
@hube2 Is there anyway to specify the category slug in the array instead of the id?
I am actually using the select type for the categories list. Found my answer here. I had to use query
instead of wp_list_categories
This worked for me, thanks!
This is my filter function. Its not working. Here category is the custom field with taxonomy type and its called category. It is supposed to pull all categories from “product_cat”.
add_filter('acf/fields/taxonomy/wp_list_categories/name=category', 'exclude_taxonomy_args', 10, 2);
function exclude_taxonomy_args( $args, $field ) {
$args['exclude'] = array(19,27,28); //the IDs of the excluded terms
return $args;
}
After adding this, I still see the categories mentioned in the exclude above.
Is it also possible to hide certain categories from being selected in the backend taxonomy field display?
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.