Hello,
I’m creating a front-end edit form with ACF pro, it’s a really powerfull tool, so thank you.
I need to pre-load value in my form. I use “acf/load_value/” it’s working with my custom post title :
//* Load existing informations
add_filter( 'acf/load_value/key=field_54dfc93e35ec4', 'tsm_load_post_title', 10, 3 );
function tsm_load_post_title( $value, $post_id, $field ) {
$value = get_post_field('post_title', $post_id);
return $value;
}
But I can’t find my taxonomies (Catégories) from custom post. I got the list, but any checkbox is selectected.
//* Load existing informations
add_filter( 'acf/load_value/key=field_54dfccb977a11', 'tsm_load_post_category', 10, 3 );
function tsm_load_post_category( $value, $post_id, $field ) {
$terms = get_the_terms( $post_id, array('espresso_event_categories') );
return $terms;
}
Do you have an idea ? Thanks a lot.
Hi JacquesMivi,
There is an option on the Taxonomy field type to “Load Terms” from the associated Post. You might try enabling that option for the field and setting the Taxonomy type in the “Taxonomy to display” filter to espresso_event_categories.
If you need to change the “Taxonomy to display” on the fly, this code should help you:
add_filter( 'acf/load_field/key=field_54dfccb977a11', 'tsm_load_post_category_field' );
function tsm_load_post_category_field($field) {
// Make sure to edit the $field object too, or AJAX lookups may return the wrong Taxonomy!
$field['taxonomy'] = 'espresso_event_categories';
return $field;
}
add_filter( 'acf/load_value/key=field_54dfccb977a11', 'tsm_load_post_category', 10, 3 );
function tsm_load_post_category( $value, $post_id, $field) {
// get terms
$term_ids = wp_get_object_terms($post_id, array('espresso_event_categories'), array('fields' => 'ids', 'orderby' => 'none'));
// error
if( is_wp_error($term_ids) ) {
return false;
}
// return
return $term_ids;
}
——————————–
Help your fellow forum-goers and moderation team; if a response solves your problem, please mark it as the solution. Thank you!
The topic ‘Front edit form – Load taxonomye value’ 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.