@@ -84,12 +84,13 @@ public static function get_post( $id, $args = array() ) {
84
84
public static function get_acf_post ( $ id , $ args = array () ) {
85
85
86
86
$ defaults = [
87
- 'meta_keys ' => null ,
88
- 'single ' => false ,
89
- 'meta_type ' => 'post ' ,
90
- 'whole_fields ' => false ,
91
- 'recursive ' => false ,
92
- 'output ' => 'OBJECT '
87
+ 'meta_keys ' => null ,
88
+ 'single ' => false ,
89
+ 'meta_type ' => 'post ' ,
90
+ 'whole_fields ' => false ,
91
+ 'max_recursion_level ' => 0 ,
92
+ 'current_recursion_level ' => 0 ,
93
+ 'output ' => 'OBJECT '
93
94
];
94
95
95
96
$ options = array_merge ( $ defaults , $ args );
@@ -102,10 +103,10 @@ public static function get_acf_post( $id, $args = array() ) {
102
103
$ acfpost ['fields ' ] = get_fields ( $ id );
103
104
104
105
// Get fields with relational post data as a whole acf object
105
- if ( isset ( $ recursive ) ) {
106
+ if ( $ current_recursion_level < $ max_recursion_level ) {
106
107
107
- // Let's avoid infinite loops by stopping recursion after one level. You may dig deeper in your view model.
108
- $ options ['recursive ' ] = apply_filters ( 'dustpress/dustpress_helper/infinite_recursion ' , false );
108
+ // Let's avoid infinite loops by default by stopping recursion after one level. You may dig deeper in your view model.
109
+ $ options ['current_recursion_level ' ] = apply_filters ( 'dustpress/query/current_recursion_level ' , ++ $ current_recursion_level );
109
110
110
111
if ( is_array ( $ acfpost ['fields ' ] ) && count ( $ acfpost ['fields ' ] ) > 0 ) {
111
112
foreach ( $ acfpost ['fields ' ] as &$ field ) {
@@ -117,7 +118,8 @@ public static function get_acf_post( $id, $args = array() ) {
117
118
'acf-field-group ' ,
118
119
'acf-field ' ,
119
120
];
120
- $ ignored_types = apply_filters ( 'dustpress/dustpress_helper/ignore_on_recursion ' , $ ignored_types );
121
+
122
+ $ ignored_types = apply_filters ( 'dustpress/query/ignore_on_recursion ' , $ ignored_types );
121
123
122
124
// A direct relation field
123
125
if ( is_object ( $ field ) && isset ( $ field ->post_type ) && ! in_array ( $ field ->post_type , $ ignored_types ) ) {
@@ -133,7 +135,7 @@ public static function get_acf_post( $id, $args = array() ) {
133
135
foreach ( $ repeater as &$ row ) {
134
136
135
137
// Post in a repeater
136
- if ( is_object ( $ row ) && isset ( $ row ->post_type ) && ! in_array ( $ field ->post_type , $ ignored_types ) ) {
138
+ if ( is_object ( $ row ) && isset ( $ row ->post_type ) && is_object ( $ field ) && isset ( $ field -> post_type ) && is_array ( $ field -> post_type ) && ! in_array ( $ field ->post_type , $ ignored_types ) ) {
137
139
$ row = self ::get_acf_post ( $ row ->ID , $ options );
138
140
}
139
141
@@ -144,7 +146,7 @@ public static function get_acf_post( $id, $args = array() ) {
144
146
}
145
147
}
146
148
}
147
- elseif ( isset ( $ wholeFields ) ) {
149
+ elseif ( true == $ whole_fields ) {
148
150
if ( is_array ( $ acfpost ['fields ' ] ) && count ( $ acfpost ['fields ' ] ) > 0 ) {
149
151
foreach ( $ acfpost ['fields ' ] as $ name => &$ field ) {
150
152
$ field = get_field_object ($ name , $ id , true );
0 commit comments