1

I have a page that has a new template, and I want to set that new template with wp-cli.

When I wp post get <id> I get an output like the following:

+-----------------------+---------------------+
| Field                 | Value               |
+-----------------------+---------------------+
| ID                    | 4                   |
| post_author           | 5                   |
| post_date             | 2012-03-09 13:11:38 |
| post_date_gmt         | 0000-00-00 00:00:00 |
| post_content          |                     |
| post_title            | Home Page           |
| post_excerpt          |                     |
| post_status           | publish             |
| comment_status        | closed              |
| ping_status           | open                |
| post_password         |                     |
| post_name             | home                |
| to_ping               |                     |
| pinged                |                     |
| post_modified         | 2015-06-04 12:23:41 |
| post_modified_gmt     | 2015-06-04 19:23:41 |
| post_content_filtered |                     |
| post_parent           | 0                   |
| guid                  | /?page_id=4         |
| menu_order            | 0                   |
| post_type             | page                |
| post_mime_type        |                     |
| comment_count         | 0                   |
+-----------------------+---------------------+

This doesn't have the attribute I am looking for page_template

When I try what seems to be the correct attribute key:
wp post update 4 --page_template='New Home Page'

I get Warning: The page template is invalid.

2

I found that in the documentation for wp-cli it says

[--<field>=<value>] Associative args for the new post. See wp_insert_post().

Which then subsequently shows:

'page_template'  => [ <string> ] // Requires name of template file, eg. template.php.

The command is wp post update 4 --page_template='new-home.php'

2

This doesn't have the attribute I am looking for page_template

Try using page_template in fields:

wp post list --post_type=page,post --fields=ID,post_title,post_name,post_type,page_template

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.