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
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.
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.
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.
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 ;
?>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With