Support

Account

Home Forums General Issues Problems with saving values to ACF-Fields when creating a new post Reply To: Problems with saving values to ACF-Fields when creating a new post

  • Hi John! Thank you for your response! It was the function “acf_get_all_field_keys”. It’s a custom function which gets the field-keys (field_123456) from the database. Here is the code:

    function acf_get_all_field_key( $meta_key ) {
    	global $wpdb;
    	$acf_fields = $wpdb->get_results( $wpdb->prepare( "
    		SELECT 'meta_value'
    		FROM '$wpdb->postmeta'
    		WHERE 'post_id' = 3077 
    		AND 'meta_key'
    		LIKE %s",
    		$meta_key
    		)
    		);
    	// get all fields with that name.
    	switch ( count( $acf_fields ) ) {
    		case 0: // no such field
    			return false;
    		case 1: // just one result. 
    			return $acf_fields[0]->meta_value;
    		default:
    			return array ($acf_fields);
    	}
    }

    I changed the post-id for this function to a fix ID of a published event, so it’s always returning values.

    I founded this function here: https://gist.github.com/mcguffin/81509c36a4a28d9c682e

    Thank you for your help! This topic is solved.