Skip to content

Commit

Permalink
chore: apply changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Lyrisbee committed Dec 26, 2023
1 parent 8f1c00f commit af8caa2
Showing 1 changed file with 22 additions and 17 deletions.
39 changes: 22 additions & 17 deletions src/triggers/class-acf-data.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,29 +30,34 @@ public function validate(): bool {
* @return array{}
*/
public function run(): array {
$data = array();

$posts = get_posts(
array(
'numberposts' => -1,
'post_type' => array( 'acf-field-group', 'acf-field' ),
)
);

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
);
}
}

0 comments on commit af8caa2

Please sign in to comment.