WordPressでショートコードを使って、投稿を動的に表示するときに現在の投稿についての情報(タイトルとか投稿時間とか・・・)を知りたい場合があります。
そんなときに使うのがget_post():投稿のレコードをデータベースから取得する
$post=get_post();
とすると下記の情報を取得することができます。
$post->ID; // (整数) 投稿 ID $post->post_author; // (整数) 作成者 ID $post->post_date; // (文字列) 投稿日時 (YYYY-MM-DD HH:MM:SS) $post->post_date_gmt; // (文字列) GMT での投稿日時 (YYYY-MM-DD HH:MM:SS) $post->post_content; // (文字列) 本文 $post->post_title; // (文字列) タイトル $post->post_category; // (整数) カテゴリー ID。V2.1以降常に0。カテゴリー取得はget_the_category() $post->post_excerpt; // (文字列) 抜粋 $post->post_status; // (文字列) 公開ステータス $post->comment_status // (文字列) コメントステータス $post->ping_status // (文字列) ピンバック/トラックバックステータス $post->post_password; // (文字列) 閲覧パスワード $post->post_name; // (文字列) スラッグ $post->to_ping // (文字列) ピン通知 URL $post->pinged // (文字列) ピン通知済み URL $post->post_modified; // (文字列) 更新日時 (YYYY-MM-DD HH:MM:SS) $post->post_modified_gmt; // (文字列) GMT での更新日時 (YYYY-MM-DD HH:MM:SS) $post->post_content_filtered; // (文字列) $post->post_parent; // (整数) 親 ID (固定ページや添付ファイルなどで使用) $post->guid // (文字列) 投稿へのリンクの書式になっている識別子。 $post->menu_order // (整数) 固定ページ の表示順序。 $post->post_type; // (文字列) 投稿タイプ $post->post_mime_type; // (文字列) 添付ファイルのとき MIME タイプ(image/png など) $post->comment_count // (整数) コメント数