WP CLI说明文档

命令概述

用于更新一个或多个WordPress文章的属性,如标题、内容、状态、作者等。

适合在需要批量修改文章字段、设置元数据或更改文章类型时使用。

参数列表

参数 说明
<id>... 要更新的文章ID列表。
[--post_author=<post_author>] 添加文章的用户ID。默认为当前用户ID。
[--post_date=<post_date>] 文章的日期。默认为当前时间。
[--post_date_gmt=<post_date_gmt>] 文章在GMT时区的日期。默认为$post_date的值。
[--post_content=<post_content>] 文章内容。默认为空。
[--post_content_filtered=<post_content_filtered>] 过滤后的文章内容。默认为空。
[--post_title=<post_title>] 文章标题。默认为空。
[--post_excerpt=<post_excerpt>] 文章摘要。默认为空。
[--post_status=<post_status>] 文章状态。默认为’draft’。
[--post_type=<post_type>] 文章类型。默认为’post’。
[--comment_status=<comment_status>] 文章是否允许评论。接受’open’或’closed’。默认为’default_comment_status’选项的值。
[--ping_status=<ping_status>] 文章是否允许ping。接受’open’或’closed’。默认为’default_ping_status’选项的值。
[--post_password=<post_password>] 访问文章的密码。默认为空。
[--post_name=<post_name>] 文章别名。默认为创建新文章时清理后的文章标题。
[--to_ping=<to_ping>] 用空格或回车分隔的要ping的URL列表。默认为空。
[--pinged=<pinged>] 用空格或回车分隔的已ping的URL列表。默认为空。
[--post_modified=<post_modified>] 文章最后修改日期。默认为当前时间。
[--post_modified_gmt=<post_modified_gmt>] 文章在GMT时区最后修改的日期。默认为当前时间。
[--post_parent=<post_parent>] 设置文章所属的父文章。默认为0。
[--menu_order=<menu_order>] 文章显示顺序。默认为0。
[--post_mime_type=<post_mime_type>] 文章的MIME类型。默认为空。
[--guid=<guid>] 用于引用文章的全局唯一ID。默认为空。
[--post_category=<post_category>] 分类名称、别名或ID的数组。默认为’default_category’选项的值。
[--tags_input=<tags_input>] 标签名称、别名或ID的数组。默认为空。
[--tax_input=<tax_input>] 以分类法名称为键的分类术语数组。默认为空。
[--meta_input=<meta_input>] 以文章元键为键的文章元值的JSON格式数组。默认为空。
[<file>] 从文件读取文章内容。如果存在此值,则--post_content参数将被忽略。传递-作为文件名将导致文章内容从STDIN读取。
--<field>=<value> 要更新的一个或多个字段。参见wp_insert_post()。
[--defer-term-counting] 批量重新计算术语计数以提高性能。

常用示例

更新单篇文章

$ wp post update 123 --post_name=something --post_status=draft

更新带有多个元值的文章

$ wp post update 123 --meta_input='{"key1":"value1","key2":"value2"}'

一次更新多篇文章

$ wp post update 123 456 --post_author=789

一次更新给定文章类型的所有文章

$ wp post update $(wp post list --post_type=page --format=ids) --post_author=123