Home › Forums › General Issues › Programmatically clear field values for all posts? › Reply To: Programmatically clear field values for all posts?
There isn’t any such thing as a “run once ever” mechanism in WP.
In addition to this, if you have many posts then looping over all of them to delete the field will more then likely time out.
This is the way I deal with this.
add_action('init', 'MY_FUNCTION_NAME');
function MY_FUNCTION_NAME() {
if (!is_user_logged_in() || get_current_user_id() != XX) {
// replace XX with your user ID
// only run this for me when I am logged in
return;
}
// query all posts
// use your field name in meta query
// only get posts where the meta_key "EXISTS"
// loop over results and delete_field() on each
}
If you have a lot of posts then this will time out the page load. If this happens reload the page until it not longer does so. This will indicate that the field has been deleted from all posts.
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.