mcpField
W
wordpress-content

wordpress-content

github.com/jezwebマーケティング・グロース1.1k1.7k 回インストール3 週間前に更新
リポジトリ

wordpress-content について

WP-CLI または REST API を使って、WordPress の投稿、固定ページ、メディア、タクソノミー、メニューなどを管理するスキルです。検証、一括操作、インポートとエクスポートも扱います。

主な機能

  1. 01投稿と固定ページの作成・更新
  2. 02メディアのアップロードと管理
  3. 03カテゴリー、タグ、メニューの管理
  4. 04WP-CLI が使えない場合の REST API 利用
  5. 05コンテンツの検索、インポート、エクスポート

活用シーン

  1. 01WordPress 投稿の公開や予約
  2. 02サイト内メディアやタクソノミーの一括更新
  3. 03サイトコンテンツの一括インポート・エクスポート
  4. 04SSH を使わず REST API でコンテンツを管理

インストール

コマンドをコピーしてターミナルで実行します。

$npx skills add https://github.com/jezweb/claude-skills --skill wordpress-content

インストール後、Claude Code で/wordpress-contentを入力して読み込まれたか確認します。

詳細

WordPress コンテンツ

WordPress のコンテンツ(投稿、固定ページ、メディア、カテゴリー、タグ、メニュー)を作成、更新、管理します。WP-CLI または REST API を使用して、サイトに公開コンテンツを作成します。

前提条件

  • 使用可能な WP-CLI SSH 接続、または REST API の認証情報(wordpress-setup スキルを使用)
  • wordpress.config.json または wp-cli.yml のサイト設定

ワークフロー

ステップ 1:操作を決定する
タスク最適な方法
投稿または固定ページを 1 件作成/編集するWP-CLI wp post create/update
投稿を一括作成するWP-CLI のループまたは REST API のバッチ処理
画像/メディアをアップロードするWP-CLI wp media import
カテゴリー/タグを管理するWP-CLI wp term
ナビゲーションメニューを更新するWP-CLI wp menu
投稿を予約するWP-CLI と --post_date を使用
複雑な HTML コンテンツを扱う一時ファイルに書き込み、WP-CLI に渡す
SSH アクセスを利用できないアプリケーションパスワードを使用した REST API
ステップ 2:コンテンツを作成する
ブログ投稿
# Simple post
wp @site post create \
  --post_type=post \
  --post_title="My New Blog Post" \
  --post_content="<p>Post content here.</p>" \
  --post_status=draft \
  --post_category=3,5

# Post from HTML file (better for long content)
wp @site post create ./post-content.html \
  --post_type=post \
  --post_title="My New Blog Post" \
  --post_status=draft \
  --post_excerpt="A brief summary of the post." \
  --post_category=3,5 \
  --tags_input="tag1,tag2"

投稿ステータス:draft、publish、pending、future(--post_date と併用)

固定ページ
wp @site post create \
  --post_type=page \
  --post_title="About Us" \
  --post_content="<h2>Our Story</h2><p>Content here...</p>" \
  --post_status=publish \
  --post_parent=0 \
  --menu_order=10
予約投稿
wp @site post create \
  --post_type=post \
  --post_title="Scheduled Post" \
  --post_content="<p>This goes live tomorrow.</p>" \
  --post_status=future \
  --post_date="2026-02-23 09:00:00"
ステップ 3:メディアをアップロードする
# Upload from URL
wp @site media import "https://example.com/image.jpg" \
  --title="Product Photo" \
  --alt="Product front view" \
  --caption="Our latest product"

# Upload from local file (requires SCP first for remote sites)
scp ./image.jpg user@host:/tmp/image.jpg
wp @site media import /tmp/image.jpg --title="Local Upload"

# Import and set as featured image in one step
wp @site media import "https://example.com/hero.jpg" \
  --title="Hero" --featured_image --post_id={id}

# List media
wp @site post list --post_type=attachment --fields=ID,post_title,guid

# Regenerate thumbnails
wp @site media regenerate --yes

投稿にアイキャッチ画像を設定する:

# Get the attachment ID from the import output, then:
wp @site post meta update {post_id} _thumbnail_id {attachment_id}
ステップ 4:タクソノミーを管理する
カテゴリー
# List categories
wp @site term list category --fields=term_id,name,slug,count

# Create category
wp @site term create category "News" --slug=news --description="Company news and updates"

# Create child category
wp @site term create category "Product News" --slug=product-news --parent=5

# Update category
wp @site term update category {term_id} --name="Updated Name"

# Assign category to post
wp @site post term add {post_id} category news
タグ
# List tags
wp @site term list post_tag --fields=term_id,name,slug,count

# Create tag
wp @site term create post_tag "new-tag"

# Add tags during post creation
wp @site post create --post_title="..." --tags_input="seo,marketing,tips"

# Add tags to existing post
wp @site post term add {post_id} post_tag seo marketing tips
ステップ 5:メニューを管理する
# List menus
wp @site menu list --fields=term_id,name,slug,count

# List items in a menu
wp @site menu item list main-menu --fields=db_id,type,title,link,position

# Add page to menu
wp @site menu item add-post main-menu {page_id} --title="About Us"

# Add custom link
wp @site menu item add-custom main-menu "Contact" "https://example.com/contact/"

# Add category archive to menu
wp @site menu item add-term main-menu category {term_id}

# Reorder (set position)
wp @site menu item update {item_id} --position=3

# Delete menu item
wp @site menu item delete {item_id}
ステップ 6:既存のコンテンツを更新する
# Update post title and content
wp @site post update {post_id} \
  --post_title="Updated Title" \
  --post_content="<p>New content.</p>"

# Update from file
wp @site post update {post_id} ./updated-content.html

# Search posts
wp @site post list --s="search term" --fields=ID,post_title

# Bulk update status
wp @site post list --post_type=post --post_status=draft --field=ID | \
  xargs -I {} wp @site post update {} --post_status=publish

# Delete (trash)
wp @site post delete {post_id}

# Delete permanently
wp @site post delete {post_id} --force
ステップ 7:投稿メタデータとカスタムフィールド
# Get all meta for a post
wp @site post meta list {post_id} --fields=meta_key,meta_value

# Get specific meta
wp @site post meta get {post_id} meta_key

# Set meta
wp @site post meta update {post_id} meta_key "meta_value"

# Add meta (allows duplicates)
wp @site post meta add {post_id} meta_key "meta_value"

# Delete meta
wp @site post meta delete {post_id} meta_key

ACF は、フィールド値と参照キー(_field_name → field_abc123)の両方を使ってフィールドを保存します。

ステップ 8:検索と置換
# Dry run first — always
wp @site search-replace "old text" "new text" --dry-run

# Execute
wp @site search-replace "old text" "new text" --precise

# Limit to specific table
wp @site search-replace "old" "new" wp_posts --precise

# Limit to specific column
wp @site search-replace "old" "new" wp_posts post_content --precise
ステップ 9:エクスポートとインポート
# Export all content
wp @site export --dir=/tmp/

# Export specific post type
wp @site export --post_type=post --dir=/tmp/

# Import
wp @site import /path/to/file.xml --authors=mapping.csv
ステップ 10:確認する
# Check the post
wp @site post get {post_id} --fields=ID,post_title,post_status,guid

# Get the live URL
wp @site post get {post_id} --field=guid

# List recent posts
wp @site post list --post_type=post --posts_per_page=5 --fields=ID,post_title,post_status,post_date

管理画面の URL と公開 URL を提示します:

  • 管理画面:https://example.com/wp-admin/post.php?post={id}&action=edit
  • 公開ページ:https://example.com/{slug}/

REST API リファレンス

WP-CLI を利用できない場合は、アプリケーションパスワード認証を使用して WordPress REST API を利用します。

認証
# Base64 encode credentials
AUTH=$(echo -n "username:xxxx xxxx xxxx xxxx xxxx xxxx" | base64)

# Use in requests
curl -s https://example.com/wp-json/wp/v2/posts \
  -H "Authorization: Basic $AUTH" \
  -H "Content-Type: application/json"
エンドポイント
リソースエンドポイント
投稿/wp-json/wp/v2/posts
固定ページ/wp-json/wp/v2/pages
メディア/wp-json/wp/v2/media
カテゴリー/wp-json/wp/v2/categories
タグ/wp-json/wp/v2/tags

すべて GET(一覧/単一項目の取得)、POST(作成)、PUT(更新)、DELETE に対応しています。

REST 経由で投稿を作成する
curl -s https://example.com/wp-json/wp/v2/posts \
  -H "Authorization: Basic $AUTH" \
  -H "Content-Type: application/json" \
  -d '{
    "title": "My New Post",
    "content": "<p>Post content here.</p>",
    "status": "draft",
    "categories": [3, 5],
    "tags": [10, 12],
    "excerpt": "Brief summary",
    "featured_media": 456
  }' | jq '{id, link, status}'
REST 経由で固定ページを作成する
curl -s https://example.com/wp-json/wp/v2/pages \
  -H "Authorization: Basic $AUTH" \
  -H "Content-Type: application/json" \
  -d '{
    "title": "About Us",
    "content": "<h2>Our Story</h2><p>Content...</p>",
    "status": "publish",
    "parent": 0
  }'
REST 経由でメディアをアップロードする
curl -s https://example.com/wp-json/wp/v2/media \
  -H "Authorization: Basic $AUTH" \
  -H "Content-Disposition: attachment; filename=photo.jpg" \
  -H "Content-Type: image/jpeg" \
  --data-binary @photo.jpg | jq '{id, source_url}'
REST 経由でカテゴリーを作成する
curl -s https://example.com/wp-json/wp/v2/categories \
  -H "Authorization: Basic $AUTH" \
  -H "Content-Type: application/json" \
  -d '{"name": "News", "slug": "news", "description": "Company updates"}'
クエリパラメーター
パラメーター用途例
per_page1 ページあたりの結果数(最大 100)?per_page=50
pageページネーション?page=2
search検索語?search=keyword
statusステータスで絞り込む?status=draft
categoriesカテゴリー ID で絞り込む?categories=3
orderby並べ替えフィールド?orderby=date
order並べ替え順序?order=desc
_fieldsレスポンスのフィールドを制限する?_fields=id,title,link

メニュー:ナビゲーションメニューの REST API サポートは限定的です。FSE テーマのブロックベースのナビゲーションには、/wp-json/wp/v2/navigation エンドポイントを利用できます。クラシックメニューには WP-CLI を使用してください。


重要なパターン

WP-CLI での HTML コンテンツ

1 文を超える内容の場合は、HTML を一時ファイルに書き込み、次のように渡します:

cat > /tmp/post-content.html << 'EOF'
<h2>Section Heading</h2>
<p>Paragraph content with <strong>bold</strong> and <a href="/link">links</a>.</p>
<ul>
  <li>List item one</li>
  <li>List item two</li>
</ul>
EOF

wp @site post create /tmp/post-content.html --post_title="My Post" --post_status=draft

複雑な HTML を --post_content に渡す場合、シェルでの引用符の扱いは不安定です。

一括処理

多数の投稿を作成する場合は、確認処理を含むループを使用します:

while IFS=, read -r title slug content_file category; do
  wp @site post create "$content_file" \
    --post_type=post \
    --post_title="$title" \
    --post_name="$slug" \
    --post_category="$category" \
    --post_status=draft
  sleep 0.5
done < posts.csv

必ず最初に draft として作成して確認し、その後、一括公開してください。

コメント