Home Forums Backend Issues (wp-admin) Auto populate ACF field from another field


Auto populate ACF field from another field

  • I hope that someone can help me with this. I’m trying to force an ACF field to auto populate from another custom field (non ACF), essentially importing in the number that has been imported into the other field (the import function being used, frustratingly ignores ACF fields when importing).

    Can anyone help?

  • Are you trying to auto populate the ACF field during the import?

    What are you using to do the import?

  • Hi John,
    Thanks for replying, essentially yes.

    The import is happening and populating a non ACF field. And I want to take what is put into the field on import from that field and copy it to an ACF field.

    Does that make sense?


  • You would need to hook into the place where the import is saving the imported value to the custom field and then use update field to put the value into the ACF field. How you do this depends on what you’re using for the import and how that works, and if that provides anywhere that you can hook into in order to extend it.

    It would help if I knew what import tool or function is being used.

  • It’s using a listings plugin, which has its own import function.

    If it helps I can create a username/password so that you can see the import.

    Annoyingly it’s not using the standard xml import. It’s importing from a CSV.


  • What is the “listings plugin”?

  • It’s part of the theme itself. I’ll have to find it tomorrow when I get back to my desktop.

    The theme is a car listings theme.

    I will find out the plugin tomorrow morning and put info on here about the import function (if I can find it) or just the Zip of the actual plugin itself, if that helps?

  • What you’re going to need to do is look through the code and figure out where the “plugin” or “theme” is actually getting and updating the values. You’ll need to see if there are any hooks their that update the value.

    Alternatively, if it updates the post you might be able to add action on the WP post_updated hook You could use get_post_meta() to get the values that the import creates and use the ACF update_field() function to update the ACF field

    Your best bet for figuring out exactly where you can hook into the process will probably be from either the theme or the plugin developer.

  • Found the associated file for the importer. I have attached it to this post 🙂 don’t know if this helps?

  • Just thought that I would check to see if that helped at all? There was another file called parsecsv.lib.php which has more information on the CSV import.

    Plus a couple of other files.

  • This is the code i’ve been working with:

    function update_price_cf( $value, $post_id, $field ) {
       $emptyprice = get_post_meta( $post_id, 'test', true );
       $importprice = get_post_meta( $post_id, '24-month-payment', true );
       if ($emptyprice == '') {
          $value = $importprice;
       return $value;
    add_filter('acf/update_value/name=test', 'update_price_cf', 10, 3);

    It sort of works.. its doesn’t work when I import in the data. Though it did work when I did an update of the post.

  • Actually, none of the files attached properly. When attaching files that contain code you need to put them in .zip files.

  • Hi John,

    Thats not a problem. The code is the closest i’ve managed to get.. any idea why it wouldn’t save on import?

  • This is not going to work because you’re using a hook for ACF. What you need to do is use a hook for either the theme or the plugin where it is updating the value. Since the import is not using ACF or integrating with it none of the ACF hooks will be called during the import.

  • Blast… I will have to get in touch with the theme/plugin dev to work out the hook.

    Thanks for your help.

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

The topic ‘Auto populate ACF field from another field’ is closed to new replies.