Home › Forums › General Issues › Change field with filter › Reply To: Change field with filter
Hi @atrevido
The acf/load_field
and acf/load_value
will modify the value after it’s loaded. It means that the value in the database is not changed at all. Instead, you can use the update_field() function to update your old posts. If you use the true/false field type, I believe you can do it like this:
$theposts = get_posts(array(
'posts_per_page' => -1,
'post_type' => 'post',
'category_name' => 'category-slug'
));
foreach( $theposts as $thepost) {
update_field('field_1234567890abc', true, $thepost->ID);
}
Where “field_1234567890abc”is the true/false field key and “category-slug” is the category slug of the posts you want to change.
Please keep in mind that you only need to execute the code once. So, when you’ve done with the code, just remove it.
I hope this makes sense 🙂
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.