Home Forums General Issues Field's key not globally unique anymore


Field's key not globally unique anymore

  • Hello,

    I realised that fields key are not globally unique anymore. I always use the acf-json folder, and before (I can’t exactly remember when) I had my field key like that "key": "field_5e56907fc3762", but not anymore… And there’s nothing wrong with my group field key : "key": "group_5e56907583762",.

    For example here is a field I get in one of my field group in acf-json folder :

    fields": [
                "key": "the-product-image", // Seems auto-generated from the label
                "label": "The product image",
                "name": "the_product_image",
                "type": "image",
                "instructions": "",
                "required": 0,
                "conditional_logic": 0,
                "wrapper": {
                    "width": "",
                    "class": "",
                    "id": ""
                "return_format": "id",
                "preview_size": "medium",
                "library": "all",
                "min_width": "",
                "min_height": "",
                "min_size": "",
                "max_width": "",
                "max_height": "",
                "max_size": "",
                "mime_types": "jpg, png, jpeg"

    I can’t find any information about it anywhere. Nothing found in release notes either. Why the change ? Is it a bug ? What’s wrong ? It’s been 4 or 5 projects in a row that I get the same behaviour from this, even at the start of the project with no other plugins.

    Some functions, hooks or other stuff makes use of the field_0e5412c364f5 key to do some magic. Might be a problem no ?

    Thanks for the help.

  • It looks like there is a filter or action on your site that is interfering with ACF saving the post slug, this is where the key is stored. Maybe another plugin or some filter in your theme. You say that this happens without other plugins, but this is not something that I’m seeing. Do you have some standard filter that you always include?

  • Wow amazing ! I had no idea ACF used post_name value.
    In my boilerplate I had this filter :

    // Replace apostrophes with dashes only once when saving a post.
    // By default wordpress remove them.
    function wm_insert_post_data_customize( $data, $postarr ) {
    	$post_id = $postarr['ID'];
    	// do nothing if post is auto-draft (when creating new post)
    	if(in_array( $data['post_status'], array( 'draft', 'pending', 'auto-draft' ) )) return $data;
    	// only if new
    	$is_new = get_post_meta($post_id, 'post_is_new', true);
    	if ( $is_new != 'true' ) {
    		$post_title = str_replace("'", "-", $data['post_title']);
    		$data['post_name'] = wp_unique_post_slug( sanitize_title( $post_title, $post_id ), $post_id, $data['post_status'], $data['post_type'], $data['post_parent'] );
    		// set the 'post_is_new' value
    		update_post_meta($post_id, 'post_is_new', 'true');
    	return $data;
    add_filter( 'wp_insert_post_data', 'wm_insert_post_data_customize', 50, 2 );

    So I added a new line after the first if(...) return $data; :
    if($data['post_type'] == 'acf-field-group' or $data['post_type'] == 'acf-field') return $data;
    And now it works like a charm.

    Thank you for the help, cheers !

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

You must be logged in to reply to this topic.