Support

Account

Home Forums Backend Issues (wp-admin) get_field() returns null after importing

Solved

get_field() returns null after importing

  • Hey friends!

    Love ACF. I’m having a strange issue with importing wordpress XML format. In my XML i declare values like so

    <wp:postmeta>
      <wp:meta_key>module_name</wp:meta_key>
      <wp:meta_value><![CDATA[blessed]]></wp:meta_value>
    </wp:postmeta>
    <wp:postmeta>
      <wp:meta_key>_module_name</wp:meta_key>
      <wp:meta_value><![CDATA[field_53c3e2b1f982b]]></wp:meta_value>
    </wp:postmeta>

    Where field ID is generated randomly. Problem I’m having is that while values DO show up in the post edit view, get_field("module_name") returns null.

    However, after I click “preview post”, all values are immediately available and visible in the post.

    Makes me think there’s some kind of additional process happening that doesn’t get triggered on wordpress import.

    Any thoughts?

    Thank you ^_^

  • Hi @alexgorbatchev

    Thanks for the bug report. I’ll do some testing with the WP export / import tool and get back to you shortly

  • Thanks @elliot! Eagerly awaiting your findings!

  • Hey @elliot, curious if you have an update on this? I’m currently blocked by this and trying to figure out what to do next… 🙁

  • I figured out what the problem was. Dug into the source quite a bit and found out that there is one field that is generated by the update post action that was missing. So, the correct way to import a field is using THREE meta fields

    
    <wp:postmeta>
      <wp:meta_key>field_53c9df3d9e257</wp:meta_key>
      <wp:meta_value><![CDATA[a:2:{s:4:"name";s:11:"module_name";s:3:"key";s:11:"module_name";}]]></wp:meta_value>
    </wp:postmeta>
    <wp:postmeta>
      <wp:meta_key>module_name</wp:meta_key>
      <wp:meta_value><![CDATA[ node-jvm ]]></wp:meta_value>
    </wp:postmeta>
    <wp:postmeta>
      <wp:meta_key>_module_name</wp:meta_key>
      <wp:meta_value><![CDATA[ field_53c9df3d9e257 ]]></wp:meta_value>
    </wp:postmeta>
    

    For some reason ACF stores entire field definition with each post, I just used a couple of fields that seemed important and this worked for me.

  • Hi @alexgorbatchev

    It sounds like the field’s settings did not exist on the 2nd website

  • I am having a similar issue. I am importing data from an outside source to populate my meta data. They show up when editing, but not on the post until I update. I compared the post_meta data before and after the update and am adding the same fields that get added on save, but they still are not showing up until I physically hit update.

    In my case it’s a repeater field and I have the following data

    photo_slider
    _photo_slider
    photo_slider_0_photo
    _photo_slider_0_photo
    photo_slider_1_photo
    _photo_slider_1_photo
    etc….

    What else am I missing. Is there something else I need to update for ACF to recognize the data for output?

  • This is still an issue in 2020. I’m using the Gravityforms User Registration add-on to create users and populate acf fields with form data. In the backend on the user profile all the fieldvalues are there, the metafields are also present in the database.
    But the fields won’t show up in the WP Rest API or with get_field, unless I manually save the user profile…
    What should we do to make the fieldvalues available right away?
    Thanks!

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

The topic ‘get_field() returns null after importing’ is closed to new replies.