acf-to-rest-api icon indicating copy to clipboard operation
acf-to-rest-api copied to clipboard

Memory limit issue querying ACF Post Objects

Open iaindurie opened this issue 5 years ago • 6 comments

I'm having an issue connecting to the wp-json/wp/v2/posts endpoint while using ACF post objects on my Wordpress site. I have a post object field set up to allow me to link to posts from other posts and pages. If I link to the same post object more than once, i.e if I select "Post 1" for the post object field on "Post 2" as well as "Post 3", I get the following error with wp_debug enabled:

Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 261904 bytes) in C:\Websites\Gatsby\wp-includes\class-wp-hook.php on line 203

I increased the memory limit but the issue remains.

I first discovered this as I was getting the following error using Gatsby.js to build a static site:

Path: /wp-json/wp/v2/posts?per_page=100&page=1
The server response was "500 Internal Server Error"

If I link to a post object only once in Wordpress, I can hit the api endpoint fine. The error only happens when I link to the same post object more than once from different posts/pages.

I'm also using the acf-to-rest-api-recursive plugin to allow me to query acf fields of post objects.

Originally posted here in Gatsby.js - #9144

iaindurie avatar Oct 17 '18 11:10 iaindurie

Same issue here. Gatsby outputs:

GraphQLError: Cannot query field "allWordpressPost" on type "Query". Did you mean "allW ordpressPage", "allWordpressWpUsers", "allWordpressWpMedia", "allWordpressWpTypes", or "wordpressPage"?

ph00lt0 avatar Nov 04 '18 13:11 ph00lt0

It's happened because the relationship between the posts caused an infinite loop.

airesvsg avatar Nov 04 '18 17:11 airesvsg

It's happened because the relationship between the posts caused an infinite loop.

Yeah also figured that out now.

ph00lt0 avatar Nov 04 '18 17:11 ph00lt0

@phoolto Did you implement any fix or just remove the relationship between the posts?

iaindurie avatar Nov 05 '18 08:11 iaindurie

@phoolto Did you implement any fix or just remove the relationship between the posts?

The only thing needed is at least one post with a featured image or turn off the featured images completely. It would definitely be good to have that fixed in the plugin but for now this should help.

ph00lt0 avatar Nov 05 '18 09:11 ph00lt0

Hey, can you explain that? I also got the error using this code:

$ids = get_field( 'weinauswahl', 'option', true );
$query->set( 'post__in', $ids ); 

sebastiantheobald avatar Feb 28 '22 10:02 sebastiantheobald