Skip to main content

wp media list

Overview

Query and list all attachments in the WordPress media library. Filter by MIME type, date, title, or any post field — and export results to JSON, CSV, or table format for auditing, migration planning, or cleanup scripts.

What It Does

wp media list is a thin wrapper around wp post list --post_type=attachment. It accepts all the same filtering arguments, plus --mime-type to filter by file format.

Syntax

wp media list [OPTIONS]

Options

FlagDescription
--mime-type=TYPEFilter by MIME type (e.g., image/jpeg, video/mp4)
--fields=FIELDSFields to display: ID, post_title, post_mime_type, guid, post_date
--format=FORMATtable, json, csv, ids, count
--post_parent=IDFilter by parent post ID
--author=IDFilter by author
--after=DATEItems uploaded after this date
--before=DATEItems uploaded before this date
--posts_per_page=NLimit results per page

Basic Usage

List all media

wp media list

Output:

+-----+------------------------------------+------------------+
| ID | post_title | post_mime_type |
+-----+------------------------------------+------------------+
| 101 | hero-banner | image/jpeg |
| 102 | product-shot | image/jpeg |
| 103 | company-profile | application/pdf |
| 104 | intro-video | video/mp4 |
+-----+------------------------------------+------------------+

Count total attachments

wp media list --format=count

Output:

342

List only images

wp media list --mime-type=image/jpeg --format=table

List all PDFs

wp media list --mime-type=application/pdf --fields=ID,post_title,guid

Output:

+-----+------------------+-----------------------------------------------+
| ID | post_title | guid |
+-----+------------------+-----------------------------------------------+
| 103 | company-profile | https://example.com/wp-content/uploads/.../company-profile.pdf |
+-----+------------------+-----------------------------------------------+

List only attachment IDs (for scripting)

wp media list --format=ids

Output:

101 102 103 104 105 ...

List media from a specific date range

wp media list --after="2025-01-01" --before="2025-12-31" --format=count

Output:

87

Export all media as CSV

wp media list \
--fields=ID,post_title,post_mime_type,post_date,guid \
--format=csv > media-audit-$(date +%Y%m%d).csv

Real-World Scenarios

Scenario 1: Find all unattached media

wp media list --post_parent=0 --format=table

Scenario 2: Find all videos uploaded this year

wp media list \
--mime-type=video/mp4 \
--after="2026-01-01" \
--fields=ID,post_title,post_date \
--format=table

Scenario 3: Delete all unattached attachments (cleanup)

for id in $(wp media list --post_parent=0 --format=ids); do
wp post delete "$id" --force
echo "Deleted unattached attachment $id"
done

Scenario 4: Audit media library by MIME type

for mime in image/jpeg image/png image/gif image/webp application/pdf video/mp4; do
COUNT=$(wp media list --mime-type="$mime" --format=count)
echo "$mime: $COUNT files"
done

Output:

image/jpeg: 215 files
image/png: 78 files
image/gif: 12 files
image/webp: 31 files
application/pdf: 6 files
video/mp4: 4 files

Quick Reference

wp media list                                    # All media
wp media list --mime-type=image/jpeg # JPEGs only
wp media list --format=count # Count
wp media list --format=ids # IDs for scripting
wp media list --post_parent=0 # Unattached media
wp media list --format=csv > media.csv # Export CSV

Next Steps