GFAPI::update_entry_field creating new database entry rather than updating the existing entry

I am using GFAPI::update_entry_field to attempt to update a particular field in a form entry. If I simply check the form entry in the usual way I see the correctly updated information. However, a Gravity Kit filter is not working so I dug deeper and discovered that it appears that at least some of the time a new row is being created in the database rather than an existing row being updated. For example, if I am working with form 5, field 10, entry 67 in the wp_gf_entry_meta table in the database I currently see 6 rows, with different values for the meta_value. There are two possible meta_values and I see both there.

It looks like I found the solution so in case someone else stumbles on this weird situation, here’s the solution. First some background on the circumstances that created the issue:

  • In my PHP code I was using a search to get the ID of the entry to update. this returned an array of entry IDs. In my case it was always an array with one element but still an array.
  • It appears to work to use this array as the entry_id in GFAPI::update_entry_field( $entry_id , $input_id , $value ); but properly this is supposed to be an integer not an array.
  • Using an array here resulted in the problem ran into. The solution is to do two things:
  1. First, in your PHP code, extract the value you need from the array so that the $entry_id is a number not an array. Use this for the update_entry_field $entry_id.
  2. But, that alone won’t fully solve the issue if you have already created a bunch of bad data in the database. I went into the wp_gf_entry_meta table and search for the right form, entry and meta_key and then deleted all the rows and then went in and resaved the entry.

I realize this is pretty deep in the weeds so I have not gone into a lot of detail about how to do what I did as I figure that anyone who has the ability to create this problem and understand it well enough to end up here will also understand the solution I laid out.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.