• Was having issues with the Advanced Custom Fields plugin’s option screen timing out on me, and I managed to track down the issue to the get_posts function it’s calling with both the numberposts and posts_per_page options set to -1… so it’s attempting to pull back every post on the site.

    While I consider this behavior problematic (and I plan on contacting the plugin’s author about it), it seems to me that such a query shouldn’t take nearly that long. When I do a select on the IDs in the posts table in mysql, I get a complete list of IDs in less than a second.

    So my question is: Is this normal behavior for the get_posts function? If so, why so un-optimized… and is there any thing I can do about it so that I can actually use Advanced Custom Fields?

Viewing 1 replies (of 1 total)
  • Thread Starter bytesmasher

    (@bytesmasher)

    Never mind, I figured it out… had to debug the core to do it ’cause I wasn’t getting any help here. Apparently WordPress caches all get_post queries (presumably to the object cache?) if the cache_results flag is not set to false. This is fine on small sites, but on sites with almost 10 thousand posts, it craps out.

    Suggestion to WordPress core devs: Add an option in the WP settings for “Cache threshold” … If the number of returned posts in a query is more than X posts, don’t cache it. Looking at the WP_Query code, this can be easily accomplished, and it would certainly result in a more stable core.

    I will also suggest to the Advanced Custom Fields developer that they add the flag in question to prevent their plugin from crapping out on large sites.

Viewing 1 replies (of 1 total)

The topic ‘How long should get_posts be taking with ~8000 posts?’ is closed to new replies.