Hey,
I need to get all the field settings assigned to a custom post type. There is this function get_field_objects() that returns the field parameters saved on a specific post (by its id). But I need the equivalent on post type.
For example, get_post_type_field_objects(‘product’) to get all field parameters assigned to WooCommerce products in general.
Does this function exist? If it doesn’t exist, how do you code it? I’m ok with the SQL.
Have a nice evening.
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,
));