Wp post update (WP-CLI)
Naar navigatie springen
Naar zoeken springen
wp post update
$ wp help wp post update NAME wp post update DESCRIPTION Updates one or more existing posts. SYNOPSIS wp post update <id>... [--post_author=<post_author>] [--post_date=<post_date>] [--post_date_gmt=<post_date_gmt>] [--post_content=<post_content>] [--post_content_filtered=<post_content_filtered>] [--post_title=<post_title>] [--post_excerpt=<post_excerpt>] [--post_status=<post_status>] [--post_type=<post_type>] [--comment_status=<comment_status>] [--ping_status=<ping_status>] [--post_password=<post_password>] [--post_name=<post_name>] [--to_ping=<to_ping>] [--pinged=<pinged>] [--post_modified=<post_modified>] [--post_modified_gmt=<post_modified_gmt>] [--post_parent=<post_parent>] [--menu_order=<menu_order>] [--post_mime_type=<post_mime_type>] [--guid=<guid>] [--post_category=<post_category>] [--tags_input=<tags_input>] [--tax_input=<tax_input>] [--meta_input=<meta_input>] [<file>] --<field>=<value> [--defer-term-counting] OPTIONS <id>... One or more IDs of posts to update. [--post_author=<post_author>] The ID of the user who added the post. Default is the current user ID. [--post_date=<post_date>] The date of the post. Default is the current time. [--post_date_gmt=<post_date_gmt>] The date of the post in the GMT timezone. Default is the value of $post_date. [--post_content=<post_content>] The post content. Default empty. [--post_content_filtered=<post_content_filtered>] The filtered post content. Default empty. [--post_title=<post_title>] The post title. Default empty. [--post_excerpt=<post_excerpt>] The post excerpt. Default empty. [--post_status=<post_status>] The post status. Default 'draft'. [--post_type=<post_type>] The post type. Default 'post'. [--comment_status=<comment_status>] Whether the post can accept comments. Accepts 'open' or 'closed'. Default is the value of 'default_comment_status' option. [--ping_status=<ping_status>] Whether the post can accept pings. Accepts 'open' or 'closed'. Default is the value of 'default_ping_status' option. [--post_password=<post_password>] The password to access the post. Default empty. [--post_name=<post_name>] The post name. Default is the sanitized post title when creating a new post. [--to_ping=<to_ping>] Space or carriage return-separated list of URLs to ping. Default empty. [--pinged=<pinged>] Space or carriage return-separated list of URLs that have been pinged. Default empty. [--post_modified=<post_modified>] The date when the post was last modified. Default is the current time. [--post_modified_gmt=<post_modified_gmt>] The date when the post was last modified in the GMT timezone. Default is the current time. [--post_parent=<post_parent>] Set this for the post it belongs to, if any. Default 0. [--menu_order=<menu_order>] The order the post should be displayed in. Default 0. [--post_mime_type=<post_mime_type>] The mime type of the post. Default empty. [--guid=<guid>] Global Unique ID for referencing the post. Default empty. [--post_category=<post_category>] Array of category names, slugs, or IDs. Defaults to value of the 'default_category' option. [--tags_input=<tags_input>] Array of tag names, slugs, or IDs. Default empty. [--tax_input=<tax_input>] Array of taxonomy terms keyed by their taxonomy name. Default empty. [--meta_input=<meta_input>] Array in JSON format of post meta values keyed by their post meta key. Default empty. [<file>] Read post content from <file>. If this value is present, the `--post_content` argument will be ignored. Passing `-` as the filename will cause post content to be read from STDIN. --<field>=<value> One or more fields to update. See wp_insert_post(). [--defer-term-counting] Recalculate term count in batch, for a performance boost. EXAMPLES $ wp post update 123 --post_name=something --post_status=draft Success: Updated post 123. # Update a post with multiple meta values. $ wp post update 123 --meta_input='{"key1":"value1","key2":"value2"}' Success: Updated post 123.
Voorbeelden
[1]:
# post_name = slug <> post_title ######################################## # wp post update 123 --post_name=something --post_status=draft Success: Updated post 123. # Update a post with multiple meta values. ######################################## # wp post update 123 --meta_input='{"key1":"value1","key2":"value2"}' Success: Updated post 123.
Eigen voorbeeld:
# Titel & name bijwerken: ######################################## # wp post update 7 --post_name="webshop-widgets" wp post update 7 --post_title="Webshop for Widgets"
Example: Get, translate & update
################################################################################ # selection_tool_translate_page_content ################################################################################ # # selection_tool_translate_page_content() { # # Initialisation ######################################## # echo ""; echo ""; echo "### selection_tool_translate_page_content()..."; echo "" # if [ -z "$path" ]; then echo " Variable 'path' not provided. Exiting"; exit; fi if [ ! -f "$path/wp-config.php" ]; then echo " File ${path}/wp-config.php not found. Exiting"; exit; fi if [ -z "$selection_tool_page_content_source" ]; then echo " Variable 'selection_tool_page_content_source' not provided. Exiting"; exit; fi if [ -z "$selection_tool_page_content_translation" ]; then echo " Variable 'selection_tool_page_content_translation' not provided. Exiting"; exit; fi if [ -z "$selection_tool_page_id" ]; then echo " Variable 'selection_tool_page_id' not provided. Exiting"; exit; fi cd $path # Check & translate ######################################## # i=$(wp post get $selection_tool_page_id --field=content) echo "Content: $i" i=${i/$selection_tool_page_content_source/$selection_tool_page_content_translation} echo "Content - translated: $i" # Post translation ######################################## # wp post update $selection_tool_page_id --post_content="$i" # }
Regenerate slugs
Simple: Just update post_name
to "", and a slug gets regenerated, based on the title. Very neat:
echo $(date +'%Y.%m.%d-%H.%M.%S') wp post list --post_type=product --field=ID | xargs wp post update --post_name="" echo $(date +'%Y.%m.%d-%H.%M.%S')
Regenerate slugs - Parallelised
This doesn't win a beauty price yet, but it works:
# Test (32||) ######################################## # # * 17.109 items # * Start: 2022.10.12-17.57.08 # * Finish: 2022.10.12-20.49.13 # * Duration: 2h49min2min52s13s = 2h51min1min5s = 2h52min5s = 10.325s # * Speed: 1,66 objects/s # # # Store product ids in array "j" ######################################## # unset j mapfile -t j < <( wp post list --post_type=product --field=ID ) # Step through index ######################################## # echo "Start: $(date +'%Y.%m.%d-%H.%M.%S')" # for i in `seq 2 32 $((${#j[@]}-1))` do # echo " Loop index: $i" # # Execute 32 threads ######################################## # wp post update ${j[$i]} --post_name="" & wp post update ${j[$i+1]} --post_name="" & wp post update ${j[$i+2]} --post_name="" & wp post update ${j[$i+3]} --post_name="" & wp post update ${j[$i+4]} --post_name="" & wp post update ${j[$i+5]} --post_name="" & wp post update ${j[$i+6]} --post_name="" & wp post update ${j[$i+7]} --post_name="" & wp post update ${j[$i+8]} --post_name="" & wp post update ${j[$i+9]} --post_name="" & wp post update ${j[$i+10]} --post_name="" & wp post update ${j[$i+11]} --post_name="" & wp post update ${j[$i+12]} --post_name="" & wp post update ${j[$i+13]} --post_name="" & wp post update ${j[$i+14]} --post_name="" & wp post update ${j[$i+15]} --post_name="" & wp post update ${j[$i+16]} --post_name="" & wp post update ${j[$i+17]} --post_name="" & wp post update ${j[$i+18]} --post_name="" & wp post update ${j[$i+19]} --post_name="" & wp post update ${j[$i+20]} --post_name="" & wp post update ${j[$i+21]} --post_name="" & wp post update ${j[$i+22]} --post_name="" & wp post update ${j[$i+23]} --post_name="" & wp post update ${j[$i+24]} --post_name="" & wp post update ${j[$i+25]} --post_name="" & wp post update ${j[$i+26]} --post_name="" & wp post update ${j[$i+27]} --post_name="" & wp post update ${j[$i+28]} --post_name="" & wp post update ${j[$i+29]} --post_name="" & wp post update ${j[$i+30]} --post_name="" & wp post update ${j[$i+31]} --post_name="" & wait # done echo "Finish: $(date +'%Y.%m.%d-%H.%M.%S')"