WP-CLIのpost createや単体テストの$this->factory->post->createのオプションで設定可能なオプションはwp_insert_postの引数で指定できるものになります。
wp_insert_post() | Function | WordPress Developer Resources
WP-CLI
カテゴリーを指定して投稿するサンプルです(カテゴリーID 2, 4, 6は作成済みのとき)。
$ wp post create --post_title="テスト投稿" --post_content="テスト投稿です。" --post_category=2,4,6 --post_status=publish
テンプレートファイルを指定して固定ページを投稿を作成するサンプルです(テーマにmy-template.phpを作成済みのとき)。
$ wp post create --post_type=page --post_title="固定ページテスト投稿" --post_content="これは固定ページのサンプルです。" --page_template=my-template.php --post_status=publish
単体テストで投稿を作成するサンプルです。
$cat1_id = $this->factory->category->create();
$cat2_id = $this->factory->category->create();
$this->factory->post->create([
'post_title' => 'テスト用投稿1',
'post_content' => 'テスト用の投稿です。',
'post_category' => [$cat1_id, $cat2_id],
] );
No comments yet.
改行と段落タグは自動で挿入されます。
メールアドレスは表示されません。