Support

Account

Home Forums General Issues How to set default value for custom field from theme

Solving

How to set default value for custom field from theme

  • Hi,

    I’m sorry for the very simple question but I only need to do one thing: My theme has some custom fields, I’d like one of those fields to have a default value so every time a new post of that type is created it has that default value.

    Except I have no idea how to import the custom fields from the theme to ACF. How would I do this?

    again sorry for the noob question!

  • Is the field group created with ACF or in the theme? In ACF there is usually a setting for default value, for most fields. If it’s a field created using PHP then you can set the default value in the field arguments. Let me know if you have more questions about doing this.

  • Hi,

    I’m pretty sure the field is created in the theme. ACF doesn’t see any fields. So my understanding is that it’s in the PHP.

    I can see in a php file how it gets displayed:

    `for($i=0; $i<$tab_count+1; $i++){
    $tab_icon = get_post_meta( $post->ID, RT_COMMON_THEMESLUG.’free_tab_’.$i.’_icon’, true);
    $tab_name = get_post_meta( $post->ID, RT_COMMON_THEMESLUG.’free_tab_’.$i.’_title’, true);
    $tab_content = get_post_meta( $post->ID, RT_COMMON_THEMESLUG.’free_tab_’.$i.’_content’, true);
    `
    But where would I find exactly where these custom fields get declared in the first place? (since there is where I would set the default value, right?)

    Thanks for the help 🙂

  • How would I go on about adding a filter in the functions file?

    (also, I got your message through mail but I can’t seem to see your reply here in the forum)

  • So your field group is either created in a plugin or somewhere in the theme. You can either modify the theme or you can add a filter to set the default value. I would go with the filter, you can add this to your functions.php file.

    I can tell by looking at this that it’s either a repeater field or a flexible content field and you’re going to need the field key in order to add the filter so you’ll need to find where the fields are created to get the field key.

    What version of ACF is being used? You’ll need to search for where the fields are created and that may be a bit different depending on the ACF version.

  • I don’t know if ACF was even used for making these, currently I just installed the latest version.

    I have no idea where they are created, so I’ll just run a mass search in all files for the word free_tab.

    That will have to happen tomorrow though, can’t reach the files right now.
    When I do find where the fields are created, how exactly would I extract the field key and use it for making a filter?

    Thanks again!

  • I did some checking and the theme I found that corresponds to the code you posted appear so be in some type of theme framework, and if you just installed ACF then these fields are probably not ACF fields. What you really need to do is contact the theme author and find out how the fields are created or how you can set a default value. It’s a premium theme so I cant really see the code.

  • That was some quick checking! Yeah that was my first approach, unfortunately they said it was not possible in an easy way (i.e in the admin panel for clients) and they might put it in an update in the future.

    However, I’ll search for where the field gets created tomorrow and then see what’s possible. Don’t know how much of the code I’m allowed to share though.

  • It wasn’t really that hard to find actually, I just did a search for RT_COMMON_THEMESLUG, the reason I initially thought it might be ACF is the loop and this 'free_tab_'.$i.'_icon' which looks very similar to how you’d get repeater fields usingget_post_meta().

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

You must be logged in to reply to this topic.