Viewing 11 replies - 1 through 11 (of 11 total)
  • Plugin Author Konrad Chmielewski

    (@hwk-fr)

    Hello,

    Thanks for the feedback. Do you have field groups that have many different locations or is set to specific post? It looks like the problem is related to the “Field Group Locations” column in the Field Groups UI (it is not related to Single Meta Save).

    This column calls:

    
    - acf_get_location_rule_values()
     -- acf_location_post->rule_values()
     ---- acf_get_grouped_posts()
    

    The function acf_get_grouped_posts() performs a get_posts(array('posts_per_page' => -1)) which seems to be the problem.

    ACF use this logic when you set a field group location on a specific post/page (this function is called using Ajax on the <select>). Without ACF Extended, you probably have trouble to set a Field Group Location to: Post == [Post Title] right? The post type post is the one that has 200k posts?

    See Screenshot: https://i.imgur.com/SLEmAxc.png

    Regards.

    Thread Starter estadio

    (@estadio)

    @hwk-fr Hi, thanks for quick reply!

    “Do you have field groups that have many different locations or is set to specific post?” -Yes.

    “Without ACF Extended, you probably have trouble to set a Field Group Location to: Post == [Post Title] right?” -Yes.

    “The post type post is the one that has 200k posts?” -No, only custom post type.

    Plugin Author Konrad Chmielewski

    (@hwk-fr)

    Hello,

    Okay thanks for the feedback. I’ll run some test and try to find a solution for users like you who have thousands of posts, and use field groups location specific to those posts.

    The next ACF update will include a feature that is heavily inspired by the column added in ACF Extended. So I’ll most probably remove this column in the next update, which should fix the issue for you.

    I’ll keep you updated here.

    Regards.

    Thread Starter estadio

    (@estadio)

    @hwk-fr Thank you!

    Plugin Author Konrad Chmielewski

    (@hwk-fr)

    Hello,

    Can you please apply the following patch? It should fix your issue.

    In the file: /acf-extended/includes/field-groups/field-groups.php line:235. Replace the following code:

    
    $values = acf_get_location_rule_values($and);
    
    if(!empty($values) && is_array($values)){
        
        foreach($values as $value_slug => $value_name){
            
            if($and['value'] != $value_slug)
                continue;
            
            if(is_array($value_name) && isset($value_name[$and['value']])){
                
                $final_name = $value_name[$and['value']];
                
            }else{
                
                $final_name = $value_name;
                
            }
            
            break;
            
        }
        
    }
    

    With this one:

    
    if(in_array($and['param'], array('post', 'page', 'page_parent'))){
    
        $final_name = get_the_title((int) $final_name);
    
    }else{
    
        $values = acf_get_location_rule_values($and);
    
        if(!empty($values) && is_array($values)){
    
            foreach($values as $value_slug => $value_name){
    
                if($and['value'] != $value_slug)
                    continue;
    
                if(is_array($value_name) && isset($value_name[$and['value']])){
        
                    $final_name = $value_name[$and['value']];
        
                }else{
        
                    $final_name = $value_name;
        
                }
    
                break;
    
            }
    
        }
    
    }
    

    Tell me if that fix your problem. If that’s the case, I’ll add it to the next patch ??

    Regards.

    Thread Starter estadio

    (@estadio)

    @hwk-fr Hi. It works great, thank you so much!

    Plugin Author Konrad Chmielewski

    (@hwk-fr)

    Hello,

    Good news! I’ll add it in the next patch. You can keep the code like that.

    Have a nice day!

    Regards.

    Thread Starter estadio

    (@estadio)

    @hwk-fr Hi! Looks like I have same problem but in other place https://gyazo.com/75a7e7073a1010e3ce2f2362ec2da2eb . These are the conditions for displaying a group of fields and a specific page is selected in them.
    https://gyazo.com/97a45e67ce827ddfc60ab5bebfcc76be

    Plugin Author Konrad Chmielewski

    (@hwk-fr)

    Hello,

    As I explained earlier, this is an ACF problem, as Post & Page conditional locations will list all posts of the post type when it loads the Select field. If you have dozen of thousands posts, it could leads to PHP memory problem like in your case.

    You can disable ACF Extended, you’ll see the problem will be the same.

    You should avoid using the conditional logic in the UI if you want to target specific posts/pages. Instead use a filter to programmatically add your location (so it isn’t loaded in Field Group UI). You can try the the following hook:

    
    add_filter('acf/load_field_group', 'my_acf_field_group_condition');
    function my_acf_field_group_condition($field_group){
    
        // Bail early if in Field Group UI
        if(acf_is_screen('edit-acf-field-group'))
            return $field_group;
        
        // Bail early if not the targeted field group
        // Replace group_123456 with the correct field group key
        if($field_group['key'] !== 'group_123456')
            return $field_group;
        
        // Add location
        $field_group['location'][] = array(
            array(
                'param'     => 'post',
                'operator'  => '==',
                'value'     => 179, // post ID
            )
        );
        
        // Return Field Group
        return $field_group;
        
    }
    

    Regards.

    Thread Starter estadio

    (@estadio)

    Hi! The solution works, but it still shows an error in the admin panel. This is not critical, it performs its function.

    Fatal error: Allowed memory size of 536870912 bytes exhausted (tried to allocate 1679360 bytes) in /var/www/new.timeout.ru/wp-includes/wp-db.php on line 2024

    Thanks again!

    Plugin Author Konrad Chmielewski

    (@hwk-fr)

    Hello,

    In the code of my previous answer, replace:

    if(acf_is_screen('edit-acf-field-group'))

    With:

    if(acf_is_screen(array('acf-field-group', 'edit-acf-field-group')))

    So the code isn’t executed in the Field Group UI.

    Regards.

Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘Fatal error: Allowed memory size…’ is closed to new replies.