'post', 'posts_per_page' => -1, 'post_status' => 'publish' ]); $data = []; foreach ($posts as $post) { $categories = wp_get_post_categories($post->ID, ['fields' => 'all']); $tags = wp_get_post_tags($post->ID); $thumbnail = get_post_thumbnail_id($post->ID); $data[] = [ 'id' => $post->ID, 'title' => $post->post_title, 'slug' => $post->post_name, 'content' => $post->post_content, 'excerpt' => $post->post_excerpt, 'status' => $post->post_status, 'published_at' => $post->post_date, 'categories' => array_map(fn($cat) => [ 'id' => $cat->term_id, 'name' => $cat->name, 'slug' => $cat->slug ], $categories), 'tags' => array_map(fn($tag) => $tag->name, $tags), 'featured_image' => $thumbnail ? wp_get_attachment_url($thumbnail) : null, ]; } file_put_contents('wp_export.json', json_encode($data, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE)); echo "Exported " . count($data) . " posts\n";