brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: wp post create reads the WordPress post body from a file

WordPress
~/tips/tip-wordpress-post-create-from-file

wp post create ./draft.html --post_title='Release notes' --post_status=draft --porcelain

Publishes or drafts a post whose content comes from an HTML file on disk.

Typing a long post body into --post_content with all the quoting is no fun. Give the command a file instead.

wp post create ./draft.html --post_title='Release notes' --post_status=draft --porcelain

When there is a file argument, the content comes from that file and --post_content is ignored. A - reads it from standard input, so another program can pipe HTML straight in. --porcelain prints only the new post ID, which is what you want in a script:

id=$(wp post create ./draft.html --post_title='Release notes' --porcelain)
wp post term add "$id" category news

Other useful fields: --post_type=page, --post_date together with --post_status=future to schedule it, and --meta_input with a JSON object for custom fields. Status defaults to draft, which I like, because nothing goes public by accident.

The file goes in as is. For a block theme, plain HTML ends up as a Classic block. If you want real blocks, the file needs the block comments, like <!-- wp:paragraph --> around each paragraph.

Further reading: wp post create

More WordPress tips wp user application-password create anna backup-script --porcelain define( 'MEDIA_TRASH', true ); wp cli check-update wp theme delete --all wp media image-size All WordPress tips (85) All topics

Link