I’d like to create a custom comment type based by thread level. The initial comment on a given post (top tier comment) would require the commenter to enter a title (I assume this would be a new database field since comments don’t typically have titles) and then enter the comment in the typical comment body field.
However, f someone were to reply directly to this comment (2nd tier comment) then they would be presented with the standard comment box that does not require a title.
Would something like this be possible in WP via creating a custom plugin, etc?
Much appreciated.
Eddie
I don’t know why somebody downvoted this question. This is a GREAT question.
Yeah, that’s totally possible. What you would want to do is use
comment_meta
to store the titles. You could add the new field into the form using the'comment_form_top'
action. It runs before name, email, and url, and still runs if the user is logged in, so you’d get the field for every user. Just echo the html directly.Then you’d want to hook into
'pre_comment_on_post'
to check if there’s a title. Usewp_die()
to exit execution if there’s nothing there.You should hook into the
'comment_post'
action to save the title. That hook passes two arguments: thecomment_id
and the comment’s approval status. The only one you should need is the comment ID. Sanitize the input withesc_attr()
and add the comment_meta.The last thing you might consider is adding some javascript that would automatically set the title and hide the field for comment replies. The comment reply links all have a class of
'comment-reply-link'
, so it wouldn’t be too difficult to hook in with jQuery.Hope that helps you get on the right track!