Home Forums Backend Issues (wp-admin) Rule page type causes memory problem


Rule page type causes memory problem

  • Hello,

    I recently had an «allowed memory size exhausted» problem and I found that it was because of page type location rule (with ACF 4.2.2 but ACF 5.3.1 does it the same way).

    When checking if page is parent (with children), ACF uses get_pages() function which returns all children as WP_Post object and store them in cache (and if you have a lot of children, this could use a lot of memory).

    So I changed function rule_match_page_type() to get only one child (since we just want to check if number of children is equal or greater than zero) and not the whole WP_Post object, but only the post ID :

    $children = get_children(array(
      'post_type' => $post->post_type,
      'post_parent' => $post->ID,
      'numberposts' => 1,
      'fields' => 'ids',

    And my memory problem is gone.

    Hope this helps.

  • Hi @tlexcellent

    You can also create your own rule. Please take a look at this page:

    I hope this helps too.

  • Hi. I know I can create own rule, this is very useful and I often use it. But why create something that already exists ? Is there any reason I don’t know that explains why ACF gets all children of a page as WP_Post objects only to see if there is one child ?

    Your code works well, but in my case, it filled my php memory and broke my page.

    I made some more tests and in my case, your location rule code runs only once and takes around 2.5 seconds (!)… with the code above it takes around 0.0010 second.

    I think it can be a good improvement for all ACF users & lovers like me.

    Thank you for your consideration.

  • Hi @tlexcellent

    I’m sorry I thought you don’t know about this custom rule. I just wanted to let you know about it so you can custom your location rules instead of modifying the core function. This way your custom rule will still be there when you updated ACF.

    Regarding why ACF gets all the children, I’m not really sure about that because I’m not the developer. For this kind of thing, please open a new ticket from so this issue ca be passed to the developer directly.

    Please explain the issue again in the ticket.

    Thank you very much!

  • Ok. Thank you. It’s done. Ticket submitted.

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

You must be logged in to reply to this topic.