wordpress - 在functions.php中检索帖子和评论的内容
我在functions.php中有下面的方法。我试图获取留下评论的帖子的标题,以及评论本身的名称、电子邮件和内容。
add_action('comment_post', 'comment_posted');
function comment_posted($comment_id) {
//what can I do here to get the original title of the post
//what can I do here to get the details of the comment (name, email, content)?
}
我尝试过 the_title() 和 get_the_title() 的变体,但没有运气。
I have the method below in functions.php. I'm trying to get at the title of the post that the comment is being left on, and also the name, email, and content of the comment itself.
add_action('comment_post', 'comment_posted');
function comment_posted($comment_id) {
//what can I do here to get the original title of the post
//what can I do here to get the details of the comment (name, email, content)?
}
I've tried variations of the_title() and get_the_title(), but no luck.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试一下:
通过使用 get_comment,您将可以访问有关评论的所有信息: http://codex.wordpress.org/Function_Reference/get_comment#Return。此外,当您使用 get_post 时,您将可以访问所有这些信息: http://codex .wordpress.org/Function_Reference/get_post#Return。
或者,您可以简单地使用:
但我更喜欢使用 get_post 函数,因为每当我需要帖子中的一条信息时,我似乎最终需要另一条信息。
希望这有帮助!
Give this a try:
By using get_comment, you'll have access to all of this information about the comment: http://codex.wordpress.org/Function_Reference/get_comment#Return. Additionally, when you use get_post, you'll have access to all of this information: http://codex.wordpress.org/Function_Reference/get_post#Return.
Alternatively, you could simply use:
but I prefer to use the get_post function because whenever I need one piece of information from the post, I seem to eventually need another piece.
Hope this helps!