You've got years of content in WordPress. Now you want to move to a static site generator, build a headless frontend, or just back up your content in a portable format.
The WordPress REST API exists, but it requires authentication setup, pagination handling, and multiple requests. Sometimes you just want a clean JSON export.
Here's how to build one.
The Export Class
<?php /** * WordPress Content Exporter */ class Content_Exporter {
/** * Export posts based on options * * @param array $options Export options * @return array */ public function export ( $options = array () ) { $defaults = array ( 'post_type' => 'post' , 'post_status' => 'publish' , 'posts_per_page' => - 1 , 'category' => '' , 'include' => array ( 'content' , 'excerpt' , 'featured_image' , 'taxonomies' , 'meta' ), );
$options = wp_parse_args ( $options , $defaults );
$args = array ( 'post_type' => sanitize_key ( $options [ 'post_type' ] ), 'post_status' => sanitize_key ( $options [ 'post_status' ] ), 'posts_per_page' => intval ( $options…