1

ばかげた何かが欠けていると確信していますが、疲れていて正確に何が欠けているのか理解できません。

私はprint_rsがうまくいく配列を持っています:

Array ( [0] => stdClass Object ( [comment_ID] => 20 [comment_post_ID] => 227 [comment_author] => admin [comment_author_email] => [comment_author_url] => [comment_author_IP] => ::1 [comment_date] => 2012-07-29 14:19:34 [comment_date_gmt] => 2012-07-29 14:19:34 [comment_content] => I'm attending this Event! [comment_karma] => 0 [comment_approved] => 1 [comment_agent] => [comment_type] => [comment_parent] => 0 [user_id] => 1 ) )

ps は、プライバシーのためにいくつかの値を削除しました。

ここで、comment_ID を取得したいのですが、ブラウザには何も出力されません。

php は次のようになります。

$current_user_comment = get_comments( array(
  'post_id' => $post->ID,
  'user_id' => get_current_user_id(),
  'number' => 1,
  'status' => 'approve',
  'type' => 'comment'
) );

print_r ( $current_user_comment );
echo $current_user_comment->comment_ID;
4

1 に答える 1

2

の出力からわかるようにprint_r$current_user_commentはオブジェクトではなく配列です。そして、目的のオブジェクトは0その配列のインデックスにあります。

$current_user_comment[0]->commentID動作します。

于 2012-07-29T15:01:45.923 に答える