Created
January 31, 2018 14:02
-
-
Save brycejacobson/b75057332229f6fe383c4740a0fb7c1c to your computer and use it in GitHub Desktop.
Update Post Meta on ACF Select Field
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Simple script used to touch/update post meta that was used in an Advanced Custom Fields select field that didn't have the reference field after an import of data thorugh a CSV. Running this script was enough to get the admin to dispaly the correct state that was already in the database. | |
require 'wp-config.php'; | |
$things = get_posts(array('numberposts' => -1, 'post_type' => 'things')); // Change 'things' to the name of your post type | |
if (!$things) { | |
echo 'No Posts'; | |
exit; | |
} | |
foreach ($things as $thing) { | |
update_post_meta($thing->ID, "state", 'MN'); // 'state' was the name of the custom post meta ACF field. | |
// add_post_meta($thing->ID, "_state", 'field_5a45552ee548e'); <-- Didn't need this when switching to update_post_meta but if you do need it this is the ACF reference field. Look for it in the database for reference. | |
} | |
echo 'Updated Things'; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment