I am in hassle proper now and I want you to assist on somewhat downside that I’ve.
For one among my shoppers I want to make use of ACF repeater discipline and populate it with empty classes from a customized taxonomy
So I began with one thing like this:
operate acf_load_my_load_cat($worth, $post_id, $discipline){
$args = array( 'taxonomy' => 'ville_formation');
$post_categories = wp_get_post_terms( get_the_ID(), 'ville_formation', array("fields" => "ids") );
if ( !empty( $post_categories ) ) {
$args['exclude'] = $post_categories;
};
$classes = get_terms( $args );
So mainly created a operate that seize my taxonomy (wich is known as ville_formation
) and outlined which time period just isn’t empty, excluded it and saved the others on a variable named $classes
$worth=array();
foreach ( $classes as $class ) {
$worth [] = array(
'field_5cd186302ef1c' => $category->identify);
};
Now with this I am creating an empty array, and for every saved time period, I create a row on my array and I assign it a key that’s the key of the sector (right here : ‘field_5cd186302ef1c’)
return $worth;
};
add_filter('acf/load_value/identify=villes_a_ajouter_III', 'acf_load_my_load_cat', 10, 3);
And ultimately I return the values and cargo my array on my repeater discipline (right here known as : ‘villes_a_ajouter_III’)
This appear to work appropriately, however on this repeater that I am populating with this operate, I’ve some radio buttons subsequent to it, and each time that I made a selection and replace my publish, the selection on this radio discipline just isn’t saved.
My downside is that my code is creating an empty array each time as a way to populate my discipline. How do I proceed to keep away from this, as a way to save my selections from this group of radio button?
So any concept so as to add/modify one thing to retailer the worth from these radio buttons?
PS : For many who need your complete code :
operate acf_load_my_load_cat($worth, $post_id, $discipline){
$args = array( 'taxonomy' => 'ville_formation');
$post_categories = wp_get_post_terms( get_the_ID(), 'ville_formation', array("fields" => "ids") );
if ( !empty( $post_categories ) ) {
$args['exclude'] = $post_categories;
};
$classes = get_terms( $args );
$worth=array();
foreach ( $classes as $class ) {
$worth [] = array(
'field_5cd186302ef1c' => $category->identify);
};
return $worth;
};
add_filter('acf/load_value/identify=villes_a_ajouter_III', 'acf_load_my_load_cat', 10, 3);
—EDIT 17/06—
Okey so i am gonna clarify somewhat bit extra.For one among my shopper i’ve to import some information to create some customized publish, with some dates/cities inside.
So in Superior Customized Area i’ve created a repeater discipline, and with a plugin i’ve created a customized taxonomy named “Villes_formation”.
So the import goes nicely, the customized taxonomy inside “villes_formation” are created with the import and present inside a customized publish kind that i’ve created for my wants.
To symbolize it it present me one thing like that
https://zupimages.web/up/19/25/ji2y.png
On my pic, the cities are on the left (On the column named “Villes”), and as you may see on the appropriate there’s some radio buttons with some selections.
The column named “Dates” affiliate the dates with cities.
This one goes nicely, and work as i would like.
However, now my shopper wish to have a one other repeater discipline with solely the cities that belong to my taxonomy ” Villes_formation” and that aren’t assigned to the publish.(there’s some that aren’t created with the import)
Let’s assume that in my customized taxonomy “Villes_formation” i’ve these strains:
-Nantes(44)
-Rennes(35)
-Paris(75)
-Niort(79)
-Good(06)
-Lyon(69)
-Poitiers(86)
-Quimper(29)
The operate that i’ve created is exhibiting solely the cities of this record that aren’t assigned to the present publish by the import.
To be extra clear here’s a pic of the second ends in my publish
https://zupimages.web/up/19/25/sxm0.png
As you may see with my record and the 2 pics, there’s 2 repeater discipline, one with the cities assigned to the publish, one with the cities that aren’t.
This operate certainly present me the “Villes_formation” that aren’t assigned to this publish, however on the second pic it’s also possible to see on the appropriate three radio buttons
which are right here to select on each metropolis.
So when i make a selection on this one it’s not saved, each time that i click on on “replace”, my operate is creating a brand new array with cities which are
not assigned to the publish, and erase my earlier selections.
My objective is to saved these selections after all !
Do i’ve to create one thing that examine the radio buttons/cities earlier than to erase them ?
I hope i’ve been clearer ^^ !