Howdy, Stranger!
It looks like you're new here. If you want to get involved, click one of these buttons!
Deleting single repeater fields does not remove entry from database
-
Basically the title says it all. When i delete a repeater field with the "remove" button it does not remove that data. Therefore posts are appearing incorrectly in search results (using "Search Everything" to index custom fields). The only way to remove the data is to overwrite it with a blank repeater field, which leads to lots of other problems
-
I had a quick look at the acf_Repeater Class in core/fields/repeater.php and came up with a quick fix. As I really hate to hack into core files I would still appreciate some cleaner solution.
Some more words of warning:
-This deletes any custom fields that match the repeater pattern of meta keys above the currently active number of rows. This might not be the desired outcome in some situations (event though I didn't come up with one yet)
-This isn't really great in terms of performance as for every column in every row two meta values are tried to be deleted. I shall try to further improve this part..
Anyhow, here is what I have by now. As already said - this is a hack and not well tested - PROCEED WITH CAUTION!
Insert this before the last line of update_value (Line Number 498)
It is important that you insert this before the last lineparent::update_value($post_id, $field, $total);
, otherwise the old number of repeater rows is already lost:$old_total = get_post_meta($post_id,$field['name'],true);
if($old_total>$total){
foreach($field['sub_fields'] as $sub_field){
for ($j=$total; $j < $old_total; $j++) {
delete_post_meta($post_id, $field['name'].'_'.$j.'_'.$sub_field['name']);
delete_post_meta($post_id, '_'.$field['name'].'_'.$j.'_'.$sub_field['name']);
}
}
}
-
I am experiencing this as well. I have added an entry to a repeater and then removed it. The meta values are still present.
-
Hi @burgers, @lopo, @deltafactory, @kraftner
I hear you loud and clear.
Thanks for the code, I'll add this in soon. Perhaps even in the next release!
Cheers
Elliot -