Support

Account

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 🙂