diff --git a/src/triggers/class-acf-data.php b/src/triggers/class-acf-data.php index e595883..d1e36d0 100644 --- a/src/triggers/class-acf-data.php +++ b/src/triggers/class-acf-data.php @@ -30,8 +30,6 @@ public function validate(): bool { * @return array{} */ public function run(): array { - $data = array(); - $posts = get_posts( array( 'numberposts' => -1, @@ -39,20 +37,27 @@ public function run(): array { ) ); - foreach ( $posts as $post ) { - $data[] = array( - 'id' => (string) $post->ID, - 'post_id' => empty( $post->post_parent ) ? null : (string) $post->post_parent, - 'type' => $post->post_type, - 'title' => $post->post_title, - 'slug' => $post->post_name, - 'excerpt' => empty( $post->post_excerpt ) ? null : $post->post_excerpt, - 'content' => $post->post_content, - 'created_at' => get_the_date( 'U', $post ), - 'updated_at' => get_the_modified_date( 'U', $post ), - ); - } - - return $data; + return array_map( + function ( $post ) { + return array( + 'id' => (string) $post->ID, + // Acf field group ID, which will be null if it's a field group. + 'post_id' => empty( $post->post_parent ) ? null : (string) $post->post_parent, + // This is an ACF type, which will be either 'acf-field' or 'acf-field-group'. + 'type' => $post->post_type, + // Field label. + 'title' => $post->post_title, + // The unique name that is automatically generated by ACF. + 'slug' => $post->post_name, + // Field name. + 'excerpt' => empty( $post->post_excerpt ) ? null : $post->post_excerpt, + // The detailed settings of a custom field, including types, validation, etc. + 'content' => $post->post_content, + 'created_at' => get_the_date( 'U', $post ), + 'updated_at' => get_the_modified_date( 'U', $post ), + ); + }, + $posts + ); } }