Whether you’re performing a content audit, migrating a site, or optimizing for SEO, extracting a structured list of WordPress posts with metadata like title, creation date, publish date, and modification date can be incredibly useful. In this guide, we’ll explore multiple methods to do just that—using WP-CLI, PHP, REST API, and WordPress XML export.
✅ Method 1: Use WP-CLI for Quick Command-Line Listing
If you have terminal access to your WordPress installation, WP-CLI offers a fast way to extract post metadata:
wp post list --post_type=post --format=csv --fields=ID,post_title,post_date,post_modified
Explanation:
post_title
: Post titlepost_date
: Creation/Publish datepost_modified
: Last updated time
📌 Pro Tip: Redirect to a CSV file using > posts.csv
.
✅ Method 2: Use a Custom PHP Script
This approach is ideal if you’re building a plugin or want to display post metadata on the frontend.
$args = [
'post_type' => 'post',
'posts_per_page' => -1,
'post_status' => 'any',
];
$posts = get_posts($args);
foreach ($posts as $post) {
echo 'Title: ' . get_the_title($post) . "<br>";
echo 'Created: ' . $post->post_date_gmt . "<br>";
echo 'Published: ' . $post->post_date . "<br>";
echo 'Modified: ' . $post->post_modified . "<br><br>";
}
Where to put this:
- Inside a custom plugin
- In a theme file (e.g.,
page-template.php
) - Via a plugin like “Code Snippets” (for temporary use)
✅ Method 3: Use the WordPress REST API
For remote tools and automation, the WordPress REST API is a powerful option.
Endpoint:
https://yourdomain.com/wp-json/wp/v2/posts?per_page=100
Each post object contains:
{
"title": { "rendered": "Post Title" },
"date": "2024-06-01T12:00:00",
"modified": "2024-06-05T15:00:00"
}
You can filter, paginate, or sort these via query parameters.
✅ Method 4: Use WordPress XML Export (Great for Migrations)
When using the built-in Tools → Export option in WordPress, you can export all posts as an .xml
file. You can then parse the file programmatically using a script like this:
import xml.etree.ElementTree as ET
tree = ET.parse('wordpress-export.xml')
root = tree.getroot()
for item in root.findall('.//item'):
if item.find('wp:post_type', ns).text == 'post':
title = item.find('title').text
post_date = item.find('wp:post_date', ns).text
modified_date = item.find('wp:post_modified', ns).text
print(f'Title: {title} | Created: {post_date} | Modified: {modified_date}')
You can even reformat the output into Excel or CSV for further analysis.
💡 Bonus: Add Representative Image Rows
In some use cases (such as generating visual content or thumbnails), it’s helpful to generate duplicated rows for featured images.
Example:
- Original:
How to Optimize WP Queries
- Duplicate:
Imagine reprezentativa pentru "How to Optimize WP Queries"
This can be automated by duplicating each row in your CSV or database output with modified text.
🛠 Use Cases
- SEO audits
- Content cleanup
- Historical comparisons
- Export for migration
- Reporting for stakeholders
📈 Conclusion
Whether you’re an SEO specialist, a developer, or a WordPress admin, extracting post metadata can greatly enhance your workflow. From WP-CLI to REST API to full XML parsing, WordPress offers powerful tools to meet your data needs.