| @@ 157-213 (lines=57) @@ | ||
| 154 | // get posts grouped by post type |
|
| 155 | $groups = acf_get_grouped_posts( $args ); |
|
| 156 | ||
| 157 | if( !empty($groups) ) { |
|
| 158 | ||
| 159 | foreach( array_keys($groups) as $group_title ) { |
|
| 160 | ||
| 161 | // vars |
|
| 162 | $posts = acf_extract_var( $groups, $group_title ); |
|
| 163 | $titles = array(); |
|
| 164 | ||
| 165 | ||
| 166 | // data |
|
| 167 | $data = array( |
|
| 168 | 'text' => $group_title, |
|
| 169 | 'children' => array() |
|
| 170 | ); |
|
| 171 | ||
| 172 | ||
| 173 | foreach( array_keys($posts) as $post_id ) { |
|
| 174 | ||
| 175 | // override data |
|
| 176 | $posts[ $post_id ] = $this->get_post_title( $posts[ $post_id ], $field, $options['post_id'] ); |
|
| 177 | ||
| 178 | }; |
|
| 179 | ||
| 180 | ||
| 181 | // order by search |
|
| 182 | if( !empty($args['s']) ) { |
|
| 183 | ||
| 184 | $posts = acf_order_by_search( $posts, $args['s'] ); |
|
| 185 | ||
| 186 | } |
|
| 187 | ||
| 188 | ||
| 189 | // append to $data |
|
| 190 | foreach( array_keys($posts) as $post_id ) { |
|
| 191 | ||
| 192 | $data['children'][] = array( |
|
| 193 | 'id' => $post_id, |
|
| 194 | 'text' => $posts[ $post_id ] |
|
| 195 | ); |
|
| 196 | ||
| 197 | } |
|
| 198 | ||
| 199 | ||
| 200 | // append to $r |
|
| 201 | $r[] = $data; |
|
| 202 | ||
| 203 | } |
|
| 204 | ||
| 205 | ||
| 206 | // optgroup or single |
|
| 207 | if( count($args['post_type']) == 1 ) { |
|
| 208 | ||
| 209 | $r = $r[0]['children']; |
|
| 210 | ||
| 211 | } |
|
| 212 | ||
| 213 | } |
|
| 214 | ||
| 215 | ||
| 216 | // return |
|
| @@ 186-242 (lines=57) @@ | ||
| 183 | // get posts grouped by post type |
|
| 184 | $groups = acf_get_grouped_posts( $args ); |
|
| 185 | ||
| 186 | if( !empty($groups) ) { |
|
| 187 | ||
| 188 | foreach( array_keys($groups) as $group_title ) { |
|
| 189 | ||
| 190 | // vars |
|
| 191 | $posts = acf_extract_var( $groups, $group_title ); |
|
| 192 | $titles = array(); |
|
| 193 | ||
| 194 | ||
| 195 | // data |
|
| 196 | $data = array( |
|
| 197 | 'text' => $group_title, |
|
| 198 | 'children' => array() |
|
| 199 | ); |
|
| 200 | ||
| 201 | ||
| 202 | foreach( array_keys($posts) as $post_id ) { |
|
| 203 | ||
| 204 | // override data |
|
| 205 | $posts[ $post_id ] = $this->get_post_title( $posts[ $post_id ], $field, $options['post_id'] ); |
|
| 206 | ||
| 207 | }; |
|
| 208 | ||
| 209 | ||
| 210 | // order by search |
|
| 211 | if( !empty($args['s']) ) { |
|
| 212 | ||
| 213 | $posts = acf_order_by_search( $posts, $args['s'] ); |
|
| 214 | ||
| 215 | } |
|
| 216 | ||
| 217 | ||
| 218 | // append to $data |
|
| 219 | foreach( array_keys($posts) as $post_id ) { |
|
| 220 | ||
| 221 | $data['children'][] = array( |
|
| 222 | 'id' => $post_id, |
|
| 223 | 'text' => $posts[ $post_id ] |
|
| 224 | ); |
|
| 225 | ||
| 226 | } |
|
| 227 | ||
| 228 | ||
| 229 | // append to $r |
|
| 230 | $r[] = $data; |
|
| 231 | ||
| 232 | } |
|
| 233 | ||
| 234 | ||
| 235 | // add as optgroup or results |
|
| 236 | if( count($args['post_type']) == 1 ) { |
|
| 237 | ||
| 238 | $r = $r[0]['children']; |
|
| 239 | ||
| 240 | } |
|
| 241 | ||
| 242 | } |
|
| 243 | ||
| 244 | ||
| 245 | // return |
|