23
20

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

post_status について

Posted at

post_status について

ちょっと気になったので調べてみた。

post_status の種類

リファレンスによると post_status は以下のとおり。

publish
A published post or page
pending
post is pending review
draft
a post in draft status
auto-draft
a newly created post, with no content
future
a post to publish in the future
private
not visible to users who are not logged in
inherit
a revision. see get_children.
trash
post is in trashbin. added with Version 2.9.

何が気になった?

「重複したらどうなるの?」
っていうところです。
パターンとしては、trash とか、future は他の post_status と重複すると思うんですよね。

例えば、「未来の記事」で探したら、ゴミ箱に入ってる記事は拾われるのかとかですかね。

では、調べていきます。

実験

準備

意図的に作り出せる状態の記事を準備します。(リビジョンとかを省きます。)

投稿_‹MyWordPress—_WordPress.png

こんな感じです。

まずは、trash 以外で、publish, pending, draft, private, future の状態の記事を作ります。
pending, draft, private については、公開日時を未来にしたものも準備します。

記事の状態は?

それぞれの記事に対して、get_post_status( $ID ) を実行して調べてみたいと思います。


予想!

private のステータス(未来) - 非公開

private

draft のステータス(未来) - 下書き

draft

pending のステータス(未来) - レビュー待ち

pending

future のステータス

future

private のステータス(過去) - 非公開

private

draft のステータス(過去) - 下書き

draft

pending のステータス(過去) - レビュー待ち

pending

publish のステータス

publish

驚くほどそのままですね…。


結果!

private のステータス(未来) - 非公開

private

draft のステータス(未来) - 下書き

draft

pending のステータス(未来) - レビュー待ち

pending

future のステータス

future

private のステータス(過去) - 非公開

private

draft のステータス(過去) - 下書き

draft

pending のステータス(過去) - レビュー待ち

pending

publish のステータス

publish

完全に一致。

スッキリしましたね。

では、ゴミ箱に入った場合はどうなるでしょうか?

実験データを全てゴミ箱に入れた後に、もう一度 get_post_status( $ID ) を実行してみます。

全て、trash になりました。


結果

trash 最強

とりあえずゴミ箱に入ってデータについては、post_status を trash で参照しない限り探せないってことがわかりました。

もう一つ気になっていた future については、公開予約状態になったものだけですね。公開日時が例え未来でも、公開予約状態になっていなければ関係無い訳ですね。

まとめ

概念としては重複する状況も、WordPress がどのように振る舞うか、今回の実験でしっかり理解することができました。

23
20
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
23
20

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?