Hi !!! I need some help with ACF!! After search for days and read many pages also try many times. Still stucked!! I draw a picture for better explain what I want to do and my state now.
- Build fabric (Repeater) which has f_image (Image) and f_name(Text) field and point it to fabricgroup (Option page).
- Build paper (Flexible Content) include fabricchoose (checkbox) and point to askform (Post type)
- Upload some images to f_image and put text in f_name
- Put the f_image (Image) and f_name(Text) into choices of fabricchoose
How I put the f_image to Label and f_name to Value of choices of fabricchoose ? I have coded some but doesn't work. Is it possible some one please point out where I code wrong? The "fabricchoose " just become blank!!
function my_acf_load_field( $addchoice ) {
//check Check rows exists
if( have_rows('facrics', 'fabricgroup') ):
while( have_rows('facrics', 'fabricgroup') ): the_row();
//put repeater data into $row
$rows = get_field('fabrics');
//Get data from Repeater
if( $rows ) {
foreach( $rows as $eachrow ) {
$parent_title = $eachrow['f_title'];
$parent_image = $eachrow['f_image'];
//make into 'choice' format > title : image
$foraddtext = $parent_title." : ".$parent_image ;
//put into 'choices'
$addchoice['choices'] = $foraddtext;
}
}
return $addchoice;
endwhile;
endif;
}
// Apply to fields named "fabricchoose".
add_filter('acf/load_field/name=fabricchoose', 'my_acf_load_field');
Aucun commentaire:
Enregistrer un commentaire