Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In Wordpress, can you get the post ID from a comment ID

Tags:

wordpress

In Wordpress, given the ID of a comment is it possible to get the ID of the post that the comment is attached to?

For example, comment with ID 1642 is attached to post with ID 172

Thanks

like image 317
badcoder Avatar asked Mar 26 '14 14:03

badcoder


People also ask

How do I find a post ID?

In URL of the Post Without Custom Permalink Structure If your permalinks settings in Settings > Permalinks are set to Plain, then the p parameter in URL is the ID of the post.

How can I get post ID from post slug?

If you want to get post id by slug in WordPress, you can do so using a function that passes the slug as a parameter and returns the post ID or Page ID. This may sound like a complicated WordPress function but it is very straightforward and easy to implement in your theme or a custom plugin.

What is Post ID?

The purpose of the POST ID is to provide a unique identifier for law enforcement personnel so that a SSN is no longer needed. The POST ID is created when a person is first appointed to a POST agency or takes a POST certified course.


1 Answers

You could use get_comment() https://codex.wordpress.org/Function_Reference/get_comment Make sure to read the parameters for the function in the above link. You must pass a variable containing an integer with this function.

<?php
    $my_id = 7;
    $comment_id_7 = get_comment( $my_id ); 
    $comment_post_id = $comment_id_7->comment_post_ID ;
?> 
like image 105
AndyWarren Avatar answered Oct 17 '22 13:10

AndyWarren