wordpress-content
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseWordPress Content
WordPress 内容管理
Create, update, and manage WordPress content — posts, pages, media, categories, tags, and menus. Produces live content on the site via WP-CLI or the REST API.
创建、更新和管理WordPress内容——文章、页面、媒体、分类、标签和菜单。通过WP-CLI或REST API在站点上生成实时内容。
Prerequisites
前提条件
- Working WP-CLI SSH connection or REST API credentials (use wordpress-setup skill)
- Site config from or
wordpress.config.jsonwp-cli.yml
- 可用的WP-CLI SSH连接或REST API凭证(使用wordpress-setup技能)
- 来自或
wordpress.config.json的站点配置wp-cli.yml
Workflow
工作流程
Step 1: Determine the Operation
步骤1:确定操作类型
| Task | Best Method |
|---|---|
| Create/edit single post or page | WP-CLI |
| Bulk create posts | WP-CLI loop or REST API batch |
| Upload images/media | WP-CLI |
| Manage categories/tags | WP-CLI |
| Update navigation menus | WP-CLI |
| Scheduled posts | WP-CLI with |
| Complex HTML content | Write to temp file, pass to WP-CLI |
| 任务 | 最佳方法 |
|---|---|
| 创建/编辑单篇文章或页面 | WP-CLI |
| 批量创建文章 | WP-CLI循环或REST API批量操作 |
| 上传图片/媒体 | WP-CLI |
| 管理分类/标签 | WP-CLI |
| 更新导航菜单 | WP-CLI |
| 定时发布文章 | 带 |
| 复杂HTML内容 | 写入临时文件,传递给WP-CLI |
Step 2: Create Content
步骤2:创建内容
Blog Posts
博客文章
bash
undefinedbash
undefinedSimple 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_type=post
--post_title="My New Blog Post"
--post_content="<p>Post content here.</p>"
--post_status=draft
--post_category=3,5
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_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)
从HTML文件创建文章(适合长内容)
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"
--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"
**Post statuses**: `draft`, `publish`, `pending`, `future` (use with `--post_date`)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"
--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`参数)Pages
页面
bash
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=10bash
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=10Scheduled Posts
定时发布文章
bash
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"bash
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"Step 3: Upload Media
步骤3:上传媒体
bash
undefinedbash
undefinedUpload from URL
从URL上传
wp @site media import "https://example.com/image.jpg"
--title="Product Photo"
--alt="Product front view"
--caption="Our latest product"
--title="Product Photo"
--alt="Product front view"
--caption="Our latest product"
wp @site media import "https://example.com/image.jpg"
--title="Product Photo"
--alt="Product front view"
--caption="Our latest product"
--title="Product Photo"
--alt="Product front view"
--caption="Our latest product"
Upload from local file (requires SCP first for remote sites)
从本地文件上传(远程站点需先通过SCP上传文件)
scp ./image.jpg user@host:/tmp/image.jpg
wp @site media import /tmp/image.jpg --title="Local Upload"
**Set featured image on a post**:
```bashscp ./image.jpg user@host:/tmp/image.jpg
wp @site media import /tmp/image.jpg --title="Local Upload"
**为文章设置特色图片**:
```bashGet the attachment ID from the import output, then:
从上传输出中获取附件ID,然后执行:
wp @site post meta update {post_id} _thumbnail_id {attachment_id}
undefinedwp @site post meta update {post_id} _thumbnail_id {attachment_id}
undefinedStep 4: Manage Taxonomy
步骤4:管理分类法
Categories
分类
bash
undefinedbash
undefinedList categories
列出所有分类
wp @site term list category --fields=term_id,name,slug,count
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"
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
wp @site term create category "Product News" --slug=product-news --parent=5
Assign category to post
为文章分配分类
wp @site post term add {post_id} category news
undefinedwp @site post term add {post_id} category news
undefinedTags
标签
bash
undefinedbash
undefinedAdd tags during post creation
创建文章时添加标签
wp @site post create --post_title="..." --tags_input="seo,marketing,tips"
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
undefinedwp @site post term add {post_id} post_tag seo marketing tips
undefinedStep 5: Manage Menus
步骤5:管理菜单
bash
undefinedbash
undefinedList menus
列出所有菜单
wp @site menu list --fields=term_id,name,slug,count
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
wp @site menu item list main-menu --fields=db_id,type,title,link
Add page to menu
向菜单添加页面
wp @site menu item add-post main-menu {page_id} --title="About Us"
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/"
wp @site menu item add-custom main-menu "Contact" "https://example.com/contact/"
Reorder (set position)
重新排序(设置位置)
wp @site menu item update {item_id} --position=3
undefinedwp @site menu item update {item_id} --position=3
undefinedStep 6: Update Existing Content
步骤6:更新已有内容
bash
undefinedbash
undefinedUpdate post title and content
更新文章标题和内容
wp @site post update {post_id}
--post_title="Updated Title"
--post_content="<p>New content.</p>"
--post_title="Updated Title"
--post_content="<p>New content.</p>"
wp @site post update {post_id}
--post_title="Updated Title"
--post_content="<p>New content.</p>"
--post_title="Updated Title"
--post_content="<p>New content.</p>"
Update from file
从文件更新内容
wp @site post update {post_id} ./updated-content.html
wp @site post update {post_id} ./updated-content.html
Bulk update status
批量更新状态
wp @site post list --post_type=post --post_status=draft --field=ID |
xargs -I {} wp @site post update {} --post_status=publish
xargs -I {} wp @site post update {} --post_status=publish
undefinedwp @site post list --post_type=post --post_status=draft --field=ID |
xargs -I {} wp @site post update {} --post_status=publish
xargs -I {} wp @site post update {} --post_status=publish
undefinedStep 7: Verify
步骤7:验证结果
bash
undefinedbash
undefinedCheck the post
查看文章信息
wp @site post get {post_id} --fields=ID,post_title,post_status,guid
wp @site post get {post_id} --fields=ID,post_title,post_status,guid
Get the live URL
获取文章的实时URL
wp @site post get {post_id} --field=guid
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
Provide the admin URL and live URL:
- Admin: `https://example.com/wp-admin/post.php?post={id}&action=edit`
- Live: `https://example.com/{slug}/`
---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}/`
---Critical Patterns
关键模式
HTML Content in WP-CLI
WP-CLI中的HTML内容
For anything beyond a sentence, write HTML to a temp file and pass it:
bash
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=draftShell quoting in is fragile for complex HTML.
--post_content对于超过一句话的内容,建议将HTML写入临时文件后再传递给WP-CLI:
bash
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在参数中使用Shell引号处理复杂HTML时容易出错。
--post_contentBulk Operations
批量操作
For creating many posts, use a loop with verification:
bash
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.csvAlways create as first, review, then bulk-publish.
draft创建多篇文章时,建议使用循环并配合验证:
bash
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建议先以(草稿)状态创建,审核后再批量发布。
draftACF Custom Fields
ACF自定义字段
If Advanced Custom Fields is installed:
bash
undefined如果已安装Advanced Custom Fields(高级自定义字段):
bash
undefinedSet ACF field
设置ACF字段
wp @site post meta update {post_id} field_name "value"
wp @site post meta update {post_id} field_name "value"
Get ACF field
获取ACF字段值
wp @site post meta get {post_id} field_name
ACF stores fields with both the field value and a reference key (`_field_name` → `field_abc123`).wp @site post meta get {post_id} field_name
ACF会同时存储字段值和引用键(`_field_name` → `field_abc123`)。REST API Alternative
REST API替代方案
When WP-CLI isn't available, use the REST API. See for patterns.
references/rest-api-endpoints.md当无法使用WP-CLI时,可以使用REST API。请参考中的使用模式。
references/rest-api-endpoints.mdReference Files
参考文件
- — REST API endpoints with authentication examples
references/rest-api-endpoints.md - — WP-CLI content management command reference
references/wp-cli-content.md
- — 包含认证示例的REST API端点文档
references/rest-api-endpoints.md - — WP-CLI内容管理命令参考文档
references/wp-cli-content.md