Support

Account

Home Forums General Issues API Functions Not Working Properly

Solving

API Functions Not Working Properly

  • the problem I’m having is quite weird, I have a couple simple get_field and update_field functions for retrieving and storing reference numbers. Unfortunately they seem to only work on the initial load of a page, so only the first time the page is loaded will it get the numbers from the fields and therefore display the proper data, after that the get_field function doesn’t retrieve anything so none of the data will display. I’ve tested this with update_field as well and nothing.

    I’ve used ACF extensively in the past and I’m almost positive I’m not missing something. The site is in it’s infancy, not many plugins and nothing really to get in the way. Is it possible that the amount of pages on this site and therefore the amount of entries in postmeta is messing it up? There are upwards of 11k pages.

  • Hi @wikimotive

    It sounds like the issue is caused by a change to the global $post object.

    ACF loads the field data from the current $post->ID.

    I would check that value on initial load, and then later in the page where the issue is.

    Is the post->ID the same number?

  • Nope doesn’t look like that’s the issue, the $post->ID stays the same the whole time. There’s very little happening on this page, like I said I’m just starting to set everything up, so all it has to do right now is find these fields from ACF and use that to display the proper data nothing else. Not to mention that specifying the post number at the end of the get_field() function also doesn’t help.

  • Hi @wikimotive

    I think I have miss understood the issue here.

    Are you able to re-explain the problem being very specific and also including your code?

    Thanks
    Elliot

  • Ok so here’s the deal from the top. I have a large amount of static pages 11,000+ on each one there is a function that is supposed to save a few random reference numbers in ACF fields which will be used to pull data from the database.

    There’s a bunch more to it but it’s not particularly relevant because even the basic stuff is not working properly.

    For the purpose of fixing this problem let’s say I have 2 function on the page only, which is basically the case at this point.

    update_field('reference_number', 92);
    $number = get_field('reference_number');
    echo $number;

    when I initially load one of the pages it will display correctly 92. If I immediately refresh the page the 92 goes away as if the field no longer exists, and I can never get it back. Also if I change the update_field() to enter a different number it will never change the number after that initial page load including if I check the actual entry in the postmeta table in the database.

    Additionally everything is there and looks correct when I check the postmeta table in the database.

  • Hi @wikimotive

    Thanks for the info,

    I’ll test this myself and have it fixed if found

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

The topic ‘API Functions Not Working Properly’ is closed to new replies.