Support

Account

Home Forums General Issues Change field type from "number" to "date"

Helping

Change field type from "number" to "date"

  • Hi there,

    I’ve created a custom field using the field type “number”

    I thus have some post with a value in this field, the value is always a “year” I mean a number with four digits, like “2020”, “1996” etc…

    Now I realise a date field might have been better, thus I would like to convert my field.

    the “issue” is, if it is an issue, how can I convert my field, I mean, the content of the field in the database won’t be the same on the “old” and “new” posts, while get_field() will behave the same way…

    So what is the best way to convert this field from number to date ?

    thank’s in advance

  • get_field will not behave the same way. For a date field ACF expects to find a value that is “YYYYMMDD”. Well honestly I don’t know if ACF will convert “YYYY” properly, but my guess in that it won’t.

    There is not easy way to convert from a number field to a date field.

    As I’ve posted in the past, the best way to deal with this is to add a new field and leave the old field alone. Use an acf/prepare_field filter to remove the old field. To deal with old posts with the old field in your template code look for a value in the new field and if it does not have a value then get the value from the old field.

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

You must be logged in to reply to this topic.