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

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

関数リファレンス/get comment

提供: WordPress Codex 日本語版
< 関数リファレンス
2017年7月5日 (水) 23:11時点におけるGblsm (トーク | 投稿記録)による版 (en:Function Reference/get_comment 12:16, 11 November 2013 MichaelH 版を流し込みました。)

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

Description

Retrieves comment data given a comment ID or comment object. You can specify, by means of the $output parameter, how you would like the results returned.

If an object is passed then the comment data will be cached and then returned after being passed through a filter. If the comment is empty, then the global comment variable will be used, if it is set.

Usage

<?php get_comment( $id, $output ); ?> 

Parameters

$comment
integer) (必須) The ID of the comment 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 = an object, ARRAY_A = an associative array of keys to values, and ARRAY_N = a numerically indexed array of values.
初期値: OBJECT

Return

(object|array) 
On success, it returns the database fields for this comment from the wp_comments table, in the format specified. On failure, null is returned. The fields returned are:
comment_ID 
(integer) The comment ID
comment_post_ID 
(integer) The post ID of the associated post
comment_author 
(string) The comment author's name
comment_author_email 
(string) The comment author's email
comment_author_url 
(string) The comment author's webpage
comment_author_IP 
(string) The comment author's IP
comment_date 
(string) The datetime of the comment (YYYY-MM-DD HH:MM:SS)
comment_date_gmt 
(string) The GMT datetime of the comment (YYYY-MM-DD HH:MM:SS)
comment_content 
(string) The comment's contents
comment_karma 
(integer) The comment's karma
comment_approved 
(string) The comment approbation (0, 1 or 'spam')
comment_agent 
(string) The comment's agent (browser, Operating System, etc.)
comment_type 
(string) The comment's type if meaningfull (pingback|trackback), and empty for normal comments
comment_parent 
(string) The parent comment's ID
user_id 
(integer) The comment author's ID if he is registered (0 otherwise)

Example

To get the author's name of a comment with ID 7:

<?php
$my_id = 7;
$comment_id_7 = get_comment( $my_id ); 
$name = $comment_id_7->comment_author;
?> 

Alternatively, specify the $output parameter:

<?php
$my_id = 7;
$comment_id_7 = get_comment( $my_id, ARRAY_A );
$name = $comment_id_7['comment_author'];
?>
<?php
//	Correct: pass a dummy variable as post_id
$the_comment = & get_comment( $dummy_id = 7 );
	
//	Incorrect: literal integer as post_id
$the_comment = & get_comment( 7 );
//	Fatal error: 'Only variables can be passed for reference' or 'Cannot pass parameter 1 by reference'
?>

Notes

Change Log

Since: 2.0.0

Source File

get_comment() is located in wp-includes/comment.php

Related

 


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

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