-->

POSTed arrays keep their values

2020-05-09 22:11发布

问题:

Today I noticed one of my Wordpress installations is behaving in a very strange way: whenever I update a post from the Dashboard, some of its extra inputs keep the values they already have (all of them are multi-dimensional arrays). For example:

[post.php?post=123&action=edit]

<input type="text" id="field_a0b" class="text" name="fields[a][0][b]" 
value="Current value" placeholder="">

If I edit that post manually (as an end user would), changing Current value to New value, then hit the Update button, $_POST['fields']['a'][0]['b'] will still contain Current value - not New value as I would expect.

This only happens with those input arrays. Also, if I change name="fields[a][0][b]" to something random, like name="fields[a][0][bbbbbbbb]", and then print that thing, then I get the value I entered in the input field!

I've hacked Wordpress files to dump data from multiple places (even from load.php), still without success.

Not sure if this is important, but the plugin generating those HTML inputs is called ACF (Advanced Custom Fields).

回答1:

I have found in the past, if I'm reusing an array, that I should unset that array each time when I'm done with it. That way you undoubtedly clear that array for reuse.