Home Forums General Issues Converting a post_meta string into ACF?


Converting a post_meta string into ACF?

  • Hello, i have a range of existing post_meta content but its in a string.

    Is there any easy way to create an ACF for the same ‘author’ and ‘content’ and have it auto populate from the existing post_meta string?

    Here is an example…

      array(1) {
        string(715) "a:2:{s:6:"author";s:26:"Author Name";s:7:"content";s:639:"Testimonial content here etc etc etc";}"

    Can that be converted to ACF without having to copy and paste them all?

  • What you have is a serialized array. Yes, there is a way to create ACF fields and to populate the field with the existing information. There would be several steps involved, but if you’re looking to make the change automatically across all posts then it is not likely.

    The first step would be to create the ACF fields that you want to store this information in.

    The next step would be to create an acf/load_value filter for each of the ACF fields that you create. In this filter you would test to see if the ACF field already has a value and if it does not you would then get the value from where it is stored in the other format and return the new value. This step will only work in the admin, meaning that you’d need to edit and save every post. I would not open and save every post, instead I would do step 3.

    For step 3 you need to edit your template files and wherever these values are used you need to see if you should use the new fields or the old fields.

    $value = get_field('new_acf_field');
    if (!$value) {
      // get the value from the old data
Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.