Support

Account

Home Forums ACF PRO Get the settings of all fields saved on a specific post type Reply To: Get the settings of all fields saved on a specific post type

  • Hey,

    I solve my topic with this script (which I do not find optimal)

    $fields_groups = get_posts(array(
        'post_type' => 'acf-field-group',
        'posts_per_page' => -1,
    ));
    
    $fields_groups = array_filter($fields_groups, function($group){
        $regex = '/i:\d;a:1:{i:0;a:3:{s:5:"param";s:9:"post_type";s:8:"operator";s:2:"==";s:5:"value";s:7:"product";}}/';
        return preg_match($regex, $group->post_content);
    });
    
    $fields_groups = array_map(function($group){
        return $group->ID;
    }, $fields_groups);
    
    $fields = get_posts(array(
        'post_type' => 'acf-field',
        'post_parent__in' => $fields_groups,
        'posts_per_page' => -1,
    ));