| | |
| | | |
| | | $defaultTitle = 'New '.$config['singular']. ' '; |
| | | foreach($data['posts'] as $index => $post) { |
| | | $progress->advance(); |
| | | $title = array_key_exists('post_title', $post['fields']) |
| | | ? sanitize_text_field($post['fields']['post_title']) |
| | | : $defaultTitle . ($index + 1); |
| | |
| | | $parent = wp_insert_post($args); |
| | | $progress->advance(); |
| | | if ($parent && !is_wp_error($parent)) { |
| | | |
| | | $childPosts = []; |
| | | $featured = $post['fields']['featured']??null; |
| | | $featuredID = null; |
| | |
| | | } |
| | | } |
| | | } |
| | | |
| | | $this->updateTimelineMetadata($parent); |
| | | } |
| | | } |
| | | return new Result( |
| | |
| | | ); |
| | | } |
| | | |
| | | /** |
| | | * Update timeline parent post with count and latest date |
| | | * @param int $parentId Parent timeline post ID |
| | | */ |
| | | private function updateTimelineMetadata(int $parentId): void |
| | | { |
| | | // Get all child posts |
| | | $children = get_children([ |
| | | 'post_parent' => $parentId, |
| | | 'post_type' => get_post_type($parentId), |
| | | 'post_status' => ['publish', 'draft'], |
| | | 'orderby' => 'date', |
| | | 'order' => 'DESC', |
| | | 'fields' => 'ids' |
| | | ]); |
| | | |
| | | // Count includes parent + children |
| | | $number = count($children) + 1; |
| | | |
| | | // Update both meta fields |
| | | update_post_meta($parentId, BASE . 'number', $number); |
| | | update_post_meta($parentId, BASE . 'latest_date', time()); |
| | | } |
| | | |
| | | // ───────────────────────────────────────────────────────────── |
| | | // Helper methods |
| | | // ───────────────────────────────────────────────────────────── |