Current status: Solving. . Done
Value not updating on custom post type
  • Hi, I'm using ACF 3.3.6 successfully across most of my site. Having no troubles with it on my posts, but have just run into an issue when using it on a custom post type. I can enter a value in the back end and save it and that value is output correctly on the front end (great) but I then cannot go and edit that value! If I try to add more text, or remove the entered value and update the custom post type, it just reverts back to the original text entered (in the back end). This is not happening on my posts, so I can't figure out what's happening on the custom post types.

    I have tried changing the field type from WYSIWYG to text area, but no difference. The code I am using to output these fields is:
    <?php
     
    if(get_field('product_specifications'))
    {
    echo '<p>' . get_field('product_specifications') . '</p>';
    } else {
    echo 'Please contact the store for specifications on this product.';
    }
     
    ?>

    Can anyone give me any help or advice on this? Thanks
  • Hi K1t,

    If you are having troubles saving the data, I would assume you have an issue with a plugin / theme conflict.

    What other plugins are you running? Also, what is the custom post type and what creates it?
  • Thanks for reply. The only other significant plugin I am running is WP e-commerce, which is also what the custom post type is. This plugin does not interfere with ACF when I am using it on normal posts or pages.....it is only affected on the custom post types which are created by WP e-commerce, where the value is not updated when saving the custom post. Any ideas would be greatly appreciated. Thanks
  • Hi K1t,

    I haven't tested ACF with WP e-commerce just yet. I'll add it to the to-do and see what I find.

    Cheers
    Elliot
  • Hi Elliot,
    Thanks for adding it to your list. I realise you must be busy, but if you have any indication of timeframe for being able to take a look, could you let me know? Just curious as I may need to look at an alternative in the mean time. Also, if I can be of assistance in any way, please don't hesitate to ask. Many thanks
  • Sorry K1t,

    I don't have a time frame, could be anything up to a month before I get around to the wp e-commerce testing.

    However, I would not just assume that it is WP e-commerce. I would setup a local WP and test acf with each plugin individually until you find the problem.
  • No worries I understand. I appreciate your replies.
    I have been doing some further testing with this and have discovered that I can update the ACF value by updating the WP e-commerce Custom Meta value (using the same field name as set up with ACF) which is also apart of the custom post type. So this satisfies my needs for now and I can continue using your great plugin. Would love to hear of any future updates on this when you get a chance to take a look. Many thanks
  • Hi K1t,

    just as a test, can you add a custom field called "this_is_a_very_unique_field".
    See if that saves. Maybe you have a simple case of custom fields being overridden by a similar name...
  • Hi K1t,

    Ive installed WP e-commerce adn confirm that I have the same problem. After looking around, I can also confirm that it is the WP e-commerce plugin which is overriding the ACF values.

    WP e-commerce has a metabox for custom meta values. This reads in the ACF values and unfortunately saves after ACF does. Therefore, it saves over the ACF values.

    I'll see if I can run my save function later on to prevent this...
  • Hi K1t,

    I have fixed the problem! I'll include this in the next release but until then, please edit /core/controllers/input.pph line 38: to
    add_action('save_post', array($this, 'save_post'), 20); // save later to avoid issues with 3rd party plugins
  • Hi Elliot, my apologies for the late reply. Thank you very much for taking a look and finding a solution. I will make that update in my files. Thanks again, really appreciate your help :)
    Kitty
  • Your fix seems to have broken saving custom fields on an original post that has been duplicated with WPML. Waiting until later to save means that ACF completely skips over the original post ID and only tries to save the metas for the duplicates. (At least that is what appeared to be happening when I logged the ID each time the update_value function ran.)

    When I removed the $save_priority variable, it began to work again.

    Could you consider adding another conditional statement to set a priority that works well with WPML?
  • Hi @rblackmon

    are you still having issues with acf 3.5.1
    I have not heard this issue from anyone else using WPML
  • Yes, I'm using 3.5.1. It was happening with a custom post type, though I'm not sure that matters. At first I was wondering if it was something I did, which is always still possible, but it definitely was resolved as soon as I removed that variable and allowed it to use the default priority for the save_post action.

    If you cannot duplicate the issue, or no one else brings it to your attention, then is there a way I can "fix" it for myself by overriding the hook in my own functions.php file so that I'm not modifying the plugin files?

    Thanks for your quick response!
  • Hi @rblackmon

    I'll do some testing and let you know what I find
  • Hello,

    To let you know, I'm having the same problem with WPML 'duplicated posts' and custom post types.

    The values will save if I create a new post and save it. Then, if I make the content 'duplicata' and try to save back, it won't.

    I will try to look at @rblackmon alternative until you have a definite fix for that :

    "When I removed the $save_priority variable, it began to work again."

    Thanks
  • @rblackmon It worked. Thanks for this fix.

    @admin, will you consider including a WPML detection/fix in next release?

    Thanks
  • @simplicix: Glad to help! Thank you for confirming it's not just me.
  • I would like to add that it is also an issue for me, but on one specific page.
    All the custom fields on other pages / custom post types are working.

    Got WPML 2.6.1 installed, and ACF 3.5.7.2, and Wordpress 3.5.

    Also, the problem appeared at a random point. It was working fine for a long time, and now after two weeks of no code changes on my behalf the problem is all of a sudden there.

    I checked with WP debug and disabled all other plugins, and disabled my own theme code to no avail. The fix described above works though, thanks for that ;) Just my two cents!
  • Hi guys,

    Thanks for all your help. I'll add this to the to-do to test out the default priority and include in the next version



    Cheers
    Elliot
  • Hi Elliot,

    I am experiencing the same issue as @simplicix and @rblackmon with WPML

    WordPress 3.5.1
    ACF 3.5.8.1
    WPML 2.6.4.1

    I've tried the fix @rblackmon provided, with no success. I can update the fields on my translated post with WPML deactivated, but as soon as I reactivate it and try to save the post my field values get overwritten with a NULL mysql value.

    Any help would be really appreciated.

    As always I'd like to say thanks for your fantastic work Elliot!

    Steve
  • Hi Elliot,

    Thanks for that link. Changing the save priority didn't have any effect. However I found a solution. The problem was that I translated the custom field group, then added a new field to the english version and then the translated version later on. The translated version was able to save the original fields copied over in the duplication process without a hitch - it was the new field which I added later on which was the problem.

    I simply deleted my translated field group and then recreated it by duplicating the original version again. In future I will remember to always edit the original field group, which I think is supposed to copy changes to the translated version by default, is that correct? (I'm looking at the checkbox on the right which is unchecked and says "Minor edit - don't update translation"). So I may have found a bug here as obviously that didn't work for me.

    Thanks again!