Home Forums Backend Issues (wp-admin) Use post title as default value


Use post title as default value

    • SMIT

    • May 24, 2019 at 9:18 pm


    is there a posibility to put the post title automaticly as the default value in a normal acf textfield? Maybe on load of the page in backend?

  • The problem is that on new posts there is no title so there would be nothing to set “default value” of the field to.

    Maybe I’m misunderstanding, can you provide more information on what you are attempting to do?

    • SMIT

    • May 25, 2019 at 1:53 am

    Hm, you are right. This could be a problem.
    So maybe i can change it to “if a field is empty, put the page-title into it“.

  • It really depends on what you are trying to do, what the ultimate goal is.

    Do you want this to be the default value and have it displayed on the site if nothing is entered into your field? or do you want to override whatever is in this field with the default value? Something else?

    You might want to take a look at the acf/load_value filter

    • SMIT

    • June 17, 2019 at 10:22 pm

    Hi John,

    sorry for this long interruption. The ultimate goal is:
    If i save the post/page/customposttype:
    – If nothing is entered in that field, a function insert the name of the post/page/customposttype in to the acf-field.

    I’m sure, it’s easy, but didn’t found the right solution.

    Thank you

    add_action('acf/save_post', 'maybe_copy_title_to_field', 20);
    function maybe_copy_title_to_field($post_id) {
      $value = get_field('custom_field_name', $post_id);
      if (!$value) {
        $value = get_the_title($post_id);
        update_field('custom_field_name', $value, $post_id);
    • SMIT

    • June 18, 2019 at 10:19 pm

    Cool, this works perfect!!!

    Thank you!


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

You must be logged in to reply to this topic.

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 Cookie Policy. If you continue to use this site, you consent to our use of cookies.