Set a Text Field Default Value

Support MB Builder Set a Text Field Default Value

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #35725
    JustLooking2022JustLooking2022
    Participant

    Hello,

    I am using MetaBox Builder and have created a text field: TITLE
    Field ID is : TITLE

    I created a Placeholder: ThisIsTheDefaultTitle

    and I have created a Default Value: ThisIsTheDefaultTitle

    I am using Meta Box Beaver Themer integrator and am trying to Insert the TITLE into a page, however, nothing is showing up if I do not enter any information into the TITLE custom field... What I would like to happen is for "ThisIsTheDefaultTitle" to be used if no TITLE has been entered on the Post/Page.

    Am I missing a setting somewhere?

    Thank you!

    JL

    #35737
    Long NguyenLong Nguyen
    Moderator

    Hi,

    The default value std helps you to show the value in appearance, this value is not saved to the database before publishing the post. Please read more here https://docs.metabox.io/creating-fields-with-code/#why-does-not-my-default-value-work

    #35760
    JustLooking2022JustLooking2022
    Participant

    Hello Thank you for your reply.

    Is there a settings where i can provide a default value to be saved to the database in the event that the field is left 'empty' when page/post is being saved/published?

    Thank you!

    #35767
    Long NguyenLong Nguyen
    Moderator

    Hi,

    There is no option to do that, but you can use the action hook rwmb_after_save_field to check the field value if it is empty and update a default value. Read more on the documentation https://docs.metabox.io/actions/rwmb-after-save-field/

    #35793
    JustLooking2022JustLooking2022
    Participant

    Thank you - this seems like a solution that could work but is way above my paygrade to implement.

    Does this do_action code need to go into functions.php? Or is it something that can be added to the specific custom field I have created with MetaBox Builder?

    Thank you!

    #35807
    Long NguyenLong Nguyen
    Moderator

    Hi,

    No need to use the function do_action() in your code, just see the examples below to hook a callback function to the action.

    You can also read more on this documentation to know how to use the action hook https://developer.wordpress.org/plugins/hooks/actions/

Viewing 6 posts - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.