get_post

Sponsored Link

投稿IDを取得し、その投稿のためにデータベースのレコードを返します。結果を返す方法を$outputパラメータの意味によって、指定することができます。

Sponsored Link

Takes a post ID and returns the database record for that post. You can specify, by means of the $output parameter, how you would like the results returned.

get_postのファンクションタグ使用方法

<?php get_post( $post, $output ); ?>

get_postのパラメーター

$post

(integer) (required)あなたが取得したい投稿IDです。整数(例:$id)を含む変数を渡す必要があります。リテラル整数(例:7)は、致命的なエラーが発生します(変数のみは参照のために渡すことができるが、参照でパラメーター1渡すことはできません。)。
デフォルト:なし

(integer) (required) The ID of the post you’d like to fetch. You must pass a variable containing an integer (e.g. $id). A literal integer (e.g. 7) will cause a fatal error (Only variables can be passed for reference or Cannot pass parameter 1 by reference).
Default: None

$output

(string) (optional)どのように結果をしたいと思います。

  • OBJECT – オブジェクトを返します。
  • ARRAY_A – 値にフィールド名の連想配列を返します。
  • ARRAY_N – フィールド値の数値配列を返します。

Default: OBJECT

(string) (optional) How you’d like the result.

  • OBJECT – returns an object
  • ARRAY_A – Returns an associative array of field names to values
  • ARRAY_N – returns a numeric array of field values

Default: OBJECT

ID7の投稿タイトルを取得するには:

To get the title for a post with ID 7:

<?php
$my_id = 7;
$post_id_7 = get_post($my_id); 
$title = $post_id_7->post_title;
?> 

また、$outputパラメータを指定します。

Alternatively, specify the $output parameter:

<?php
$my_id = 7;
$post_id_7 = get_post($my_id, ARRAY_A);
$title = $post_id_7&#91;'post_title'&#93;;
?> 


<?php
##Correct: pass a dummy variable as post_id
$the_post = &amp; get_post( $dummy_id = 7 );

##Incorrect: literal integer as post_id
$the_post = &amp; get_post( 7 );
//Fatal error: 'Only variables can be passed for reference' or 'Cannot pass parameter 1 by reference'
?>

戻り値

返されるフィールドは次のとおりです。:

The fields returned are:

ID

(integer) 投稿ID

(integer) The post ID

post_author

(integer)投稿著者のID

(integer) The post author’s ID

post_date

(string) 投稿日時(YYYY-MM-DD HH:MM:SS)

(string) The datetime of the post (YYYY-MM-DD HH:MM:SS)

post_date_gmt

(string)ポストのGMT日時(YYYY-MM-DD HH:MM:SS)

(string) The GMT datetime of the post (YYYY-MM-DD HH:MM:SS)

post_content

(string) 投稿の内容

(string) The post’s contents

post_title

投稿のタイトル

(string) The post’s title

post_category

投稿カテゴリーのID。これは、常にWordPress2.1以降kara0(ゼロ)になることに注意してください。投稿のカテゴリー
または複数カテゴリーを取得するには、get_the_category()を使用してください。

(integer) The post category’s ID. Note that this will always be 0 (zero) from wordpress 2.1 onwards. To determine a post’s category or categories, use get_the_category().

post_excerpt

(string)投稿抜粋

(string) The post excerpt

post_status

(string) 投稿ステータス(公開|レビュー待ち|下書き|プライベート|静的|オブジェクト|添付ファイル|予約|ゴミ箱)

(string) The post status (publish|pending|draft|private|static|object|attachment|inherit|future|trash)

comment_status

(string) コメントステータス(公開|閉じている|登録のみ)

(string) The comment status (open|closed|registered_only)

ping_status

(string) ピンバック/トラックバックステータス(公開|閉じている)

(string) The pingback/trackback status (open|closed)

post_password

(string) 投稿パスワード

(string) The post password

post_name

(string) 投稿のURLスラッグ

(string) The post’s URL slug

to_ping

(string) pingを実行するURL

(string) URLs to be pinged

pinged

(string) 既にpingを実行したURL

(string) URLs already pinged

post_modified

(string) 記事の最終更新日時 (YYYY-MM-DD HH:MM:SS)

(string) The last modified datetime of the post (YYYY-MM-DD HH:MM:SS)

post_modified_gmt

(string) 記事の最終更新GMTの日時(YYYY-MM-DD HH:MM:SS)

(string) The last modified GMT datetime of the post (YYYY-MM-DD HH:MM:SS)

post_content_filtered

(string)

(string)

post_parent

(integer) 親投稿のID(添付ファイル、など)

(integer) The parent post’s ID (for attachments, etc)

guid

(string) 投稿へのリンク。注:1つは、パーマリンクになるGUIDに依存することはできず、そしてまた、投稿への有効なリンクになる事を期待することはできません。現時点で投稿へのリンクであることで発生する、ただの一意の識別子にすぎません。

(string) A link to the post. Note: One cannot rely upon the GUID to be the permalink (as it previously was in pre-2.5), Nor can you expect it to be a valid link to the post. It’s merely a unique identifier, which so happens to be a link to the post at present.

menu_order

(integer)

(integer)

post_type

(string)(投稿|ページ|添付ファイル)

(string) (post|page|attachment)

post_mime_type

(string) MIMEタイプ(添付ファイル、など)

(string) Mime Type (for attachments, etc)

comment_count

(integer) コメント数

(integer) Number of comments

ソースファイル

get_post()は、wp-includes/post.phpとwp-app.php内に位置しています。

get_post() is located in wp-includes/post.php and wp-app.php.

References

NBが動作していないget_postメソッドは:”このトピックは、新しい回答が閉鎖されています。”

get_post method not working NB: “This topic has been closed to new replies.”

Sponsored Link