Home › Forums › Backend Issues (wp-admin) › Changing custom field names › Reply To: Changing custom field names
there isn’t any way to do this with a single SQL query and you’ll need to do this in PHP so that you can do one query to find what needs to be changes and then loop over these results and do a second query on each row to make the update.
First you need to select the correct fields, these are quick sql examples
‘SELECT * FROM wp_postmeta WHERE meta_value = {$field_key}’
Extract the post ID, and meta_key from the results
// get the correct meta key
$field_meta_key = substr($meta_value, 1)
You will need to loop over these results in PHP and update each row
update the field key reference
UPDATE wp_postmeta WHERE post_id = "$post_id" AND meta_key = "$field_meta_key" SET meta_key = "{$new_meta_key}"
update the field
`
UPDATE wp_postmeta WHERE post_id = “$post_id” AND meta_key = “$meta_key” SET meta_key = “_{$new_meta_key}”
‘
Even this would be prone to causing issues
I would not do this, no one sees the field names and I would live with what I built and learn from the experience to use better naming in the future.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.