Les commandes WP CLI pour les posts (articles, pages...).

Gérer les posts de votre site web WordPress directement depuis l’invite de commandes pour gagner du temps grâce à WP CLI.

Gérer les termes de taxonomie d’un post

BASH
                    # Ajouter un terme existant de taxonomie à un post
# wp post term set {postID} {taxonomy} {term_value}
wp post term set 1337 category marketing

# Attribuer un terme inexistant de taxonomie à un post
# wp post term add {postID} {taxonomy} {term_slug}
wp post term add 1337 category marketing

# Supprimer un terme existant de taxonomie d'un post
# wp post term remove {postID} {taxonomy} {term_slug}
wp post term remove 1337 category marketing

# Obtenir toutes les categories d'un post
# wp post term list {postID} {taxonomy}
wp post term list 1337 category
                

Gérer les metas d’un post

BASH
                    # Ajouter une meta à un post
# wp post meta set {postID} {meta_key} {meta_value}
wp post meta set 1337 _wp_page_template about.php

# Editer la meta d'un post
# wp post meta update {postID} {meta_key} {meta_value}
wp post meta update 1337 _wp_page_template about.php

# Obtenir la meta d'un post
# wp post meta get {postID} {meta_key}
wp post meta get 1337 _wp_page_template

# Supprimer la meta d'un post
# wp post meta delete {postID} {meta_key}
wp post meta delete 1337 _wp_page_template

# Obtenir toutes les metas d'un post
# wp post meta list {postID}
wp post meta list 1337
                

Obtenir les posts

BASH
                    # wp post list
wp post list

# Obtenir tous les IDs
# wp post list --field={field}
wp post list --field=ID

# Obtenir toutes les pages
# wp post list --post_type={post_type}
wp post list --post_type=page

# Obtenir tous les articles en brouillon
# wp post list --post_type={post_type} --post_status={post_status}
wp post list --post_type=papostge --post_status=draft

# Obtenir les posts ayant pour ID une liste d'ids
# wp post list --post__in={postIDs}
wp post list --post__in=42,1337
                

Obtenir les informations d’un post

BASH
                    # wp post get {postID}
wp post get 1337

# Enregister le contenu d'un post dans un fichier
# wp post get {postID} --field={field} > {file}
wp post get 1337 --field=content > file.txt
                

Générer des posts

BASH
                    # Générer des pages
# wp post generate --count={posts_count} --post_type={post_type}
wp post generate --count=42 --post_type='page'
                

Vérifier si un post existe

BASH
                    # wp post exists {postID}
wp post exists 1337
                

Éditer un post

BASH
                    # wp post edit {postID}
wp post edit 1337
                

Ouvrir un éditeur de texte pour modifier le contenu d’un post.

Supprimer un post

BASH
                    # Supprimer sans passer par le corbeille
# wp post delete {postID} --force
wp post delete 1337 --force

# Supprimer toutes les pages
# wp post delete $(wp post list --post_type={post_type} --format=ids)
wp post delete $(wp post list --post_type='page' --format=ids)

# Supprimer toutes les pages dans la corbeille
# wp post delete $(wp post list --post_type={post_type} --post_status=trash --format=ids)
wp post delete $(wp post list --post_type='page' --post_status=trash --format=ids)
                

Dupliquer un post

BASH
                    # wp post create --from-post={postID} --post_title={post_title}
wp post create --from-post=1337 --post_title='Mon nouveau titre'
                
BASH
                    # Mettre à jour un article
# wp post update {postID} --post_type={post_type} --post_title={post_title} --post_status={post_status}
wp post update 1337 --post_title='Mon article' --post_status=publish
# Mettre à jour un article dont le contenu texte vient d'un fichier
# wp post update {postID} --post_type={post_type} --post_title={post_title} --post_status={post_status}
wp post update 1337 ./mon-contenu.txt --post_title='Mon article' --post_status=publish
# Mettre à jour une page
# wp post update {postID} --post_type={post_type} --post_title={post_title} --post_status={post_status}
wp post update 1337 --post_type=page --post_title='Ma super page' --post_status=publish
# Mettre à jour une page et renseigner des metas vaues
# wp post update {postID} --post_type={post_type} --post_title={post_title} --meta_input={metas}
wp post update 1337 --post_type=page --post_title='Ma super page' --meta_input='{"key1":"value1","key2":"value2"}'
                

Voir la documentation pour les paramètres

BASH
                    # Créer un article
# wp post create --post_type={post_type} --post_title={post_title} --post_status={post_status}
wp post create --post_title='Mon article' --post_status=publish

# Créer un article dont le contenu texte vient d'un fichier
# wp post create --post_type={post_type} --post_title={post_title} --post_status={post_status}
wp post create ./mon-contenu.txt --post_title='Mon article' --post_status=publish

# Créer une page
# wp post create --post_type={post_type} --post_title={post_title} --post_status={post_status}
wp post create --post_type=page --post_title='Ma super page' --post_status=publish

# Créer une page et renseigner des metas vaues
# wp post create --post_type={post_type} --post_title={post_title} --meta_input={metas}
wp post create --post_type=page --post_title='Ma super page' --meta_input='{"key1":"value1","key2":"value2"}'
                

Voir la documentation pour les paramètres