$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>pages - How do I set and list page_template with wpcli?|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

pages - How do I set and list page_template with wpcli?

matteradmin10PV0评论

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.

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.

Share Improve this question asked Jun 4, 2015 at 19:40 Mike LyonsMike Lyons 2032 silver badges9 bronze badges
Add a comment  | 

2 Answers 2

Reset to default 6

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'

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
Post a comment

comment list (0)

  1. No comments so far