1

I'm having trouble setting the page template with wp-cli. According to this post, How do I set and list page_template with wpcli, it looks like:

wp post create --post_type=page --page_template='template-name.php'

should work, but it only returns "Error: The page template is invalid." Any thoughts? I've tried creating the page first and then updating using wp post update 14 --page_template='template-name.php' and that says "Success: Updated post 14." but nothing is changed when I look at the page in the Wordpress admin.

Thanks for help on this. Today is my first day working with wp-cli and it is incredible. I wish I would have come across this a long time ago.

2
  • Of course. Now I figured it out. The problem was that my templates were in a folder in my theme called "templates" (I use foundationPress). I did a wp post meta list post_name="post-name" and is showed that it is in the folder templates. Then I changed the above code to wp post create --post_type=page --page_template='template/template-name.php' and it worked fine.
    – Chuck
    Commented Jan 23, 2016 at 8:04
  • btw, in case someone in the same situation finds this the command wp post meta list post_name="post-name" is incredibly useful, especially if you use advanced custom fields.
    – Chuck
    Commented Jan 23, 2016 at 8:10

1 Answer 1

1

I wrote this as a comment, but should have put it here.

The problem was that my templates were in a folder in my theme called "templates"

I found this out by doing:

wp post meta list post_name="post-name" 

and is showed that it is in the folder templates. Then I changed the above code to

wp post create --post_type=page --page_template='template/template-name.php' 

This worked fine

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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