Support

Account

Home Forums Pre-purchase Questions How to replace existing plugin fields with ACF fields?

Solving

How to replace existing plugin fields with ACF fields?

  • Hi, I’m trying to make an existing plugin (tickera) more intuitive for clients to manage. I love the “custom fields builder” in ACF which allows me to control how the custom fields meta box appears etc. Is there a way that I can replace the existing fields with ACF fields so that I can adjust the meta boxes etc?

  • There is not likely a simple 1-to-1 replacement, but it depends on how that other plugin stores values which I am not familiar with.

    If the plugin stores every value as a separate meta field the way ACF does and the data that it stores is the same as what ACF stores then you can create fields with the same field names and ACF will automatically pull in and save the field to the right place.

    However, if the fields are not stored the same as ACF then you would need to use new field names and create an acf/save_post action and in this action you would need to get the ACF field values and convert them whatever the other plugin requirements that other plugin requires and then update the values to the other plugin’s fields.

  • Hi,
    Tell me if you want me to create a new thread, but this is basically the same question. I have another plugin that saves meta data to a custom post type. When I create a field in ACF with the same key I can see the value in that field, just as expected.
    When I edit the field and save it does not update. What I think happens is that the other plugin hooks in later and update the previous value, from the original text field.

    Is there any way to change the priority of the acf hook?

    I have tried this, to save the new value the then replcade, without any success.

    add_action('acf/save_post', 'my_acf_save_post');
    function my_acf_save_post( $post_id ) {
        $new_value = get_field('profile_subtitle_new', $post_id);
        update_field('profile_subtitle', $new_value, $post_id);
    }

    Fredrik

  • @fredriksundlof-se the problem you are seeing is probably because the other plugin’s fields are still active on the page and have the same name. Values entered into the fields for the other plugin are probably overriding the ACF values after ACF updates.

    As far as your filter goes. It may be working, but again, this filter is probably running before the other fields saves values and it is saving values based on what is entered into those fields and overwriting what is done by ACF.

    In order to make the change you need to deactivate the other plugin.

  • Yes, I think that this is the problem.

    But I do need the other plugin though. That plugin has its own settings for the post and there it has its own text field with the same name (key). The problem is that this field is kinda hidden and its hard for me to explain for the users how to find it.
    I want to make this field more avalible by put it right under the Title field. Just as I have mange easy with ACF.
    But as you said, now I have 2 fields with the same key and both are executing the update for it, ACF first, and then the other plugin. Hence my question about priorities. Can I run the ACF update later?

    Thanks for your support on this issue John! 🙂

  • There is only a couple of ways that I can think of doing this without removed the other plugins fields from the page.

    That would be building a custom JavaScript application that copies the values of the ACF fields to the other plugins fields as they are updated. As well as the reverse of this, altering the new ACF fields when the plugin fields are changed in case the user decided to edit them there.

    The other way would be to figure out when the other plugin fires to update the values from the input, and create an action that fires after the plugin’s action and then overwrite all of the values with the value submitted in the ACF fields. Basically create your own custom save process for every field.

  • I did manage to accomplish this with a native wordpress function.

    add_action( 'save_post', 'change_meta_on_update', 100, 3 );
    function change_meta_on_update( $post_id, $post, $update ) {
    	$new = get_post_meta( $post_id, 'titel', true );
    	update_post_meta( $post_id, 'profile_subtitle', $new );
    }

    Simply this fires after the post update (prio 100). Takes the value I wanted from ACF (“title”) and then updates the other value (“profile_subtitle”).

    🙂

  • ACF fires on the save_post action with a priority of 10, mor that likely so does the other plugin. The other plugin going first is, well, if they both have a priority of 10 then it can be a coin flip and as to do with the order that each add_action() is called. Using a priority of 100 on your action ensures that it happens after both plugins are done.

  • If ACF (or any other plugin) is active on the site you do not need to include its files as they are all being included in the wordpress initialization process. The only tricky part is that you don’t know the order in which files are included and yours might be included before the ACF files are included, therefor you should probably wait for the init action or even later action before using it.

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

You must be logged in to reply to this topic.

We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.