Wait? Did you just state get_comment_ancestors()
does not exist? What were they thinking…
We can do this by looping through the entire comment thread until we find the top level comment. We identify it by parent_comment
being set to 0
:
/**
* Return the top parent comment ID
*
* @param $comment_id
* @return comment id
*/
function cc_get_top_level_comment_id_wpse_265978($comment_id){
if (!is_numeric($comment_id)) return;
$parent_comment_id = 1;
// loop comment thread until we find the one which has parent comment ID set to 0
while($parent_comment_id > 0) {
$comment = get_comment($comment_id);
$comment_current_id = $comment->comment_ID;
$parent_comment_id = $comment->comment_parent;
$comment_id = $parent_comment_id;
}
return $comment_current_id;
}
Related Posts:
- Add option to disable comments on a per posts basis?
- Paginate result set from $wpdb->get_results()
- Change Comment Author Display Name
- Check If comment author is registered
- Success message in comment form
- How to allow the reply link to remain on the comment form after I have reached my 10 nested comment limit?
- Threaded comments – deleting parent comment leads to orphan comments
- Is there a hook for comment author link?
- How can I edit the email sent when a new comment is received?
- How to remove or replace the log-in link for comment replies?
- How to Block Access to Standard Login Flow and Comment Flow
- Add Comment Custom Field
- Remove link preview in discussion dashboard
- Can’t add default comments to custom post type
- Prevent Contributor to show comment list
- where to modify get_comment_author_link()?
- Does Akismet plugin expose any hooks, functions, class that can work with custom code?
- Comments Feed & Custom Post Statuses
- Multiple Comment Forms in a single page [closed]
- Displaying comments with a walker: how to distinguish between parent and child comments
- Count parent comments & replies separately?
- How to modify comments form using comment_form()?
- Capability for allowing user to post own comments without moderation
- Comment form problem with comment_author_url and HTML5 input placeholders
- How would I count the number of times a comment meta field’s value is in a post’s entire comments?
- Get comment content by comment ID
- stackexchange-like submit comment window
- Cannot get local avatars to show [closed]
- Limit user to one comment
- Is comment metadata included in the export file?
- Get a List of All Commenters on the Current Post
- WordPress comments on users profile
- wordpress threaded comments – customize nested ul / how child ul is displayd
- How to make a secure blog that is completely private?
- identify and delete spam comments from 3000 pending comments
- Hide comments column in WordPress backend
- Removing the limit on the number of nested comments
- How to call my custom WordPress Comment form without getting the comments?
- How unrequire comment text in wordpress post
- Auto delete comment if Contains
- How would I add the comment count to this sub-pages of current page snippet
- save_post action hook for comments
- Automatically increase comment karma on comment save
- How to handle upvotes and downvotes of disqus comments after importing disqus comments to wordpress?
- All users/comments suspected as bot? [closed]
- Show comments of a user post only when they are login
- comments in Admin
- How to get and use the the number of days since the last comment?
- Get all child comments ids from parent comment id
- How do I add class to an admin comment?
- Best way to tell if a comment is from a user?
- How to make comments private for commentor and post author
- Name of comment field differs on different sites
- WordPress Spam Comment Filter
- Which hook do I use to edit pending comment count on wordpress dashboard?
- Add comment_id on Comments page within wp-admin
- comment button shows only logged in users wordpress
- Getting comments of an specefic user
- I update a post and it creates a pingback? Any idea why?
- How can I embed comments plugin to my own website?
- get only one last comment from each post
- Applying same style to all the comments on the page
- Customise Comment form
- Limit action in comment according to IP
- How to get recent comment link
- stumped on add_action hook to delete_comment – any ideas?
- Can I create a new comment type?
- Avoiding calls to theme-compat
- Allow tags between shortcode in comments
- How / where is the wp_query object created for RSS feeds?
- Delete/Spam Comment Button
- Who approved a comment, to show up in dashboard
- Cannot Remove Title Reply from Custom Comment Template for Signup Page
- comment just attachment .. reply just text … can I do that?
- I have an odd field with a purple background, mentioning HTML-codes to use while leaving comments
- No comment Section but still got a Comment
- How to prevent users/authors from seing IP/email of new commentators?
- Why are my threaded comments not quite working? [closed]
- $post->comment_status always returns ‘closed’
- Order comments in admin by custom date
- WordPress Comments – Divide by conversation like Medium.com
- How to replace anonymous comment form with a registration form on wordpress?
- What is wrong with this? [closed]
- Redirect first time comments
- Posting XML in comment section
- How to check if post has previous_comments_link() and next_comments_link()
- Comment text area in single blog post and show comments if approved
- comment files and s
- Comments – Ensure the correct field is highlighted for nested replies
- How to ‘If Author’ Comments Check
- How to hold all comments for moderation, including author’s comments on own post
- Comment Blacklist
- Subscribe to a post’s comments without posting a comment yourself
- WordPress error when sending comment
- WordPress Page Template: Comment Filtering with Querystring
- Modify “Recent Comments” List in WP-Admin
- comments are going to spam
- Why default comment fields don’t show up?
- How to enable truly anonymous posting in bbPress forums? [closed]
- comment_approved custom value