Support

Account

Home Forums General Issues Default Value not appearing in existing posts

Solving

Default Value not appearing in existing posts

  • Quick question – this seems like it should be easy, but I just can’t figure it out.

    I downloaded the plugin, installed it, set up a field group, and a field, and went into my theme’s single.php file and added that little bit of code. In the back end of the site, there’s a field at the bottom of each of my posts, and if I put text into that field, it appears in the front end of the site.

    My problem is that when I put text into the Default Value in the plugin’s settings for my field on the back end of the site, it does not appear automatically (in the back end) in the fields at the bottoms of each of my posts (and therefore, obviously, does not appear in the front end either).

    How do I get the text I put into the Default Value in the plugin’s settings to populate out into the boxes at the bottoms of each of my posts?

    (I’m pretty much a novice and do not know php.)

  • Hi Samtranum,

    That actually makes sense. The default value will appear in the editor but doesn’t actually save along with the post until you save the post.

    Any exisiting posts won’t have these values to show. Only posts edited (and saved) after the plugin and field were created will show values.

  • Hi ausdamo,

    Thanks for that — I went and created a new post and that you’re right, the default value does show up in the box under the new post.

    That’s very disappointing, though. I guess this is the wrong plugin for me. Because I want the text to show up under every post on my site, and that apparently would require me to go back through thousands of previous posts and manually enter it there.

    Is there really no way to get ACF to insert a bit of text at the bottom of every post on my site, both the already published ones, and new ones?

  • You don’t even need ACF to do that, you can edit your site’s template to display whatever you want.

  • If you want the default value to be displayed for fields that don’t have a value set then you need to build a filter to do the work and ACF provides a hook for this https://www.advancedcustomfields.com/resources/acf-load_value/

    Also, I believe that if you use the field key to get the value in your template that ACF will automatically show the default value…. but I’m not 100% certain of this. It’s been a while since I looked that part of the ACF code.

  • To display default field value, you can use echo acf_get_field('field_xxxxxxxxxxx')["default_value"]; where field_xxxxxxxxxxx is the field key. You can tweak it further to get default value if saved value not existing.

  • I was calling get_field('my_custom_field_name'); and getting an object with a bunch of NULL, 0 and empty fields. woops!

    Thank you @wellmade-online !
    All I needed to do is change my call to acf_get_field('my_custom_field_name') and all values (including the default value I needed) were populated.

Viewing 7 posts - 1 through 7 (of 7 total)

You must be logged in to reply to this topic.