Home › Forums › Add-ons › Repeater Field › Fill up repeater fields with category › Reply To: Fill up repeater fields with category
(the entire code create something like this)
function my_load_cat($value, $post_id, $field){
$args = array( 'parent' => 779 );
$post_categories = wp_get_post_terms( get_the_ID(), 'category', array("fields" => "ids") );
if ( !empty( $post_categories ) ) {
$args['exclude'] = $post_categories;
};
$categories = get_categories( $args );
foreach ( $categories as $category ) {
$value[]=array(
'field_5cd186302ef1c' => $category->name
);
};
return $value;
};
}
add_filter('acf/load_value/name=villes_a_ajouter_III', 'my_load_cat', 10, 3);
So i tried to add your answer to my function, and this is creating me something like
function my_load_cat($value, $post_id, $field){
$args = array( 'parent' => 779 );
$post_categories = wp_get_post_terms( get_the_ID(), 'category', array("fields" => "ids") );
if ( !empty( $post_categories ) ) {
$args['exclude'] = $post_categories;
};
$categories = get_categories( $args );
if (!empty($value)) {
// this repeater already has a value do not change it
return $value
}
else{
foreach ( $categories as $category ) {
$value= array(
array(
'field_5cd186302ef1c' => $category->name
)
);
};
return $value;
};
}
add_filter('acf/load_value/name=villes_a_ajouter_III', 'my_load_cat', 20, 3);
But not working, any idea to help me ? Thanks for your answer john !
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.