Home › Forums › Backend Issues (wp-admin) › Adding new field to existing posts › Reply To: Adding new field to existing posts
While Kevin’s suggestion will get done what you want to do, I find it a much better alternative to check fields in the template. For example, I would never add something like
<span><?php the_field('my-field'); ?></span>
without checking to see if it has a value first
<?php
if (get_field('my-field')) {
?><span><?php the_field('my-field'); ?></span><?php
}
?>
Since I’m already checking the value I would alter my check to:
<?php
$value = get_field('my-field');
if (!$value) {
$value = 'my default value';
}
?><span><?php echo $value; ?></span>
This makes in unnecessary for me to retroactively add the field to the database.
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.