We are having a problem that appears to be isolated to the wp-admin area. We have ACF fields on a custom post type. They save in wp-admin without a problem.
However, we have noticed that some fields cannot be accessed by our code in the wp-admin section. For example, we have a PDF generator in the back end that we run via this URL:
This simply pulls some posts and their meta, and outputs a PDF.
When run at this URL, our repeater fields don’t return correctly to display on the PDF. They return ‘1’ when we print_r them, which is the number of rows in the repeater field but this used return an array. The exact same code worked up until very recently.
Now, the function that runs this PDF generator is also called on the front end during a particular process. For ease of understanding, assume this is during the checkout.
The generated PDF from this front end process correctly outputs the repeater fields.
Hence we have a very odd error whereby some fields behaviour differently depending on where they are accessed i.e. wp-admin side versus code that is run as part of a front end process.
ACF Version 5.7.9
WP Version 5.0.2
(We have disabled all plugins and gone back to stock themes, but the problem persists)
There are a couple of causes for a repeater field returning the number of rows instead of an array.
The first is that ACF doesn’t know what post ID to use to get the field, but I don’t think this is the case. It would only be the case if the field key reference was missing in the database. Since you are getting the number of rows, then you are getting something, so also an indicator that this is not the problem. However, this could also happen if ACF does not know the ID of the post in some cases depending on other fields and what it thinks the post ID is. Supplying the correct post ID when like
get_field('field-name', $post_id) would resolve this.
The second thing that could cause this is that there is a filter or action somewhere that is interfering with the queries that ACF needs to do to get the repeater. I suspect this is more likely the issue. With recent changes to WP, there could be a change, but you’ve already tried the standard deactivate plugins and switch themes. However, are you still using and/or code that generates the PDF? If not then I’d try removing that and create a different output and see if you’re still only getting the number of rows.
You must be logged in to reply to this topic.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
© 2022 Advanced Custom Fields.