• 赤色のリンクは、まだ日本語Codexに存在しないページ・画像です。英語版と併せてご覧ください。(詳細

このWikiはいつでも誰でも編集できます

関数リファレンス/get post

提供: WordPress Codex 日本語版
< 関数リファレンス
2010年4月28日 (水) 22:39時点におけるKz (トーク | 投稿記録)による版 (en:Function Reference/get post 03:51, 21 April 2010 Martythornley)

(差分) ← 古い版 | 最新版 (差分) | 新しい版 → (差分)
移動先: 案内検索

Description

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.

Usage

%%%<?php get_post( $id, $output ); ?> %%%

Parameters

$post
integer) (必須) 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).
初期値: なし
$output
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
初期値: OBJECT

Example

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; ?> %%%

Alternatively, specify the $output parameter:

%%%<?php $my_id = 7; $post_id_7 = get_post($my_id, ARRAY_A); $title = $post_id_7['post_title']; ?> %%%

%%%<?php

    1. Correct: pass a dummy variable as post_id

$the_post = & get_post( $dummy_id = 7 );

    1. Incorrect: literal integer as post_id

$the_post = & get_post( 7 ); // Fatal error: 'Only variables can be passed for reference' or 'Cannot pass parameter 1 by reference' ?>%%%

Return

The fields returned are:

ID 
(integer) The post ID
post_author 
(integer) The post author's ID
post_date 
(string) The datetime of the post (YYYY-MM-DD HH:MM:SS)
post_date_gmt 
(string) The GMT datetime of the post (YYYY-MM-DD HH:MM:SS)
post_content 
(string) The post's contents
post_title 
(string) The post's title
post_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) The post excerpt
post_status 
(string) The post status (publish|pending|draft|private|static|object|attachment|inherit|future)
comment_status 
(string) The comment status (open|closed|registered_only)
ping_status 
(string) The pingback/trackback status (open|closed)
post_password 
(string) The post password
post_name 
(string) The post's URL slug
to_ping 
(string) URLs to be pinged
pinged 
(string) URLs already pinged
post_modified 
(string) The last modified datetime of the post (YYYY-MM-DD HH:MM:SS)
post_modified_gmt 
(string) The last modified GMT datetime of the post (YYYY-MM-DD HH:MM:SS)
post_content_filtered 
(string)
post_parent 
(integer) The parent post's ID (for attachments, etc)
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 mearly a unique identifier, which so happens to be a link to the post at present.
menu_order 
(integer)
post_type 
(string) (post|page|attachment)
post_mime_type 
(string) Mime Type (for attachments, etc)
comment_count 
(integer) Number of comments

Source File

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

References

Related

関数リファレンステンプレートタグ目次もご覧ください。


この記事は翻訳時に編集が必要であるとマークされていました。その為Codex原文が大きく編集されている可能性があります。内容を確認される際は原文を参照していただき、可能であれば本項目へ反映させてください。よりよいCodexを作成するためのお手伝いをお願いします。

最新英語版: WordPress Codex » Function Reference/get post最新版との差分