Support

Account

Home Forums ACF PRO Front edit form – Load taxonomye value

Solved

Front edit form – Load taxonomye value

  • 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!

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.