Wp post get (WP-CLI): verschil tussen versies

Uit De Vliegende Brigade
Naar navigatie springen Naar zoeken springen
Regel 79: Regel 79:
 
== Example: Get, translate & update ==
 
== Example: Get, translate & update ==
  
 +
<pre>
 +
################################################################################
 +
# 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"
 +
#
 +
}
 +
</pre>
  
 
== Zie ook ==
 
== Zie ook ==
  
 
* [[Wp post (WP-CLI) | wp post]]
 
* [[Wp post (WP-CLI) | wp post]]

Versie van 7 sep 2022 20:08

wp post get: Retrieve details about a post.

NAME

  wp post get

DESCRIPTION

  Gets details about a post.

SYNOPSIS

  wp post get <id> [--field=<field>] [--fields=<fields>] [--format=<format>]

OPTIONS

  <id>
    The ID of the post to get.

  [--field=<field>]
    Instead of returning the whole post, returns the value of a single field.

  [--fields=<fields>]
    Limit the output to specific fields. Defaults to all fields.

  [--format=<format>]
    Render output in a particular format.
    ---
    default: table
    options:
      - table
      - csv
      - json
      - yaml
    ---

EXAMPLES

    # Save the post content to a file
    $ wp post get 123 --field=content > file.txt

Simple example

$ wp post get 51110

+-----------------------+---------------------------------------------+
| Field                 | Value                                       |
+-----------------------+---------------------------------------------+
| ID                    | 51110                                       |
| post_author           | 4                                           |
| post_date             | 2020-05-05 18:13:15                         |
| post_date_gmt         | 2020-05-05 18:13:15                         |
| post_content          |                                             |
| post_title            | Widgets for ABC - Kies je Toepassing        |
| post_excerpt          |                                             |
| post_status           | publish                                     |
| comment_status        | closed                                      |
| ping_status           | closed                                      |
| post_password         |                                             |
| post_name             | widgets-voor-abc-kies-je-apparaat           |
| to_ping               |                                             |
| pinged                |                                             |
| post_modified         | 2021-03-12 13:17:54                         |
| post_modified_gmt     | 2021-03-12 12:17:54                         |
| post_content_filtered |                                             |
| post_parent           | 0                                           |
| guid                  | http://en.s1/?page_id=51110                 |
| menu_order            | 0                                           |
| post_type             | page                                        |
| post_mime_type        |                                             |
| comment_count         | 0                                           |
| nl                    | null                                        |
+-----------------------+---------------------------------------------+

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"
	#
}

Zie ook