[wp-hackers] Working with date field in comment form

Otto otto at ottodestruct.com
Wed Mar 3 22:39:24 UTC 2010


On Wed, Mar 3, 2010 at 4:02 PM, Tareq Hasan <tareq1988 at gmail.com> wrote:
> Hi,
> I am trying to add date field to my comment form. There will be fields like
> *Day*, *Month* and *Year*. I want to validate the dates with checkdate()
> function for a valid date. The comment will be posted to db as supplied in
> the form. I want to do this with default form post action
> site_url/wp-comments-post.php . But i didn't find any way to hooking the *
> $commentdata['comment_date']* variable.
>
> How can i do that, please give me suggestions.

comment_date and comment_date_gmt get set in the wp_new_comment()
function. You can't override them before the comment gets inserted
into the database, but you can change them after the fact.

You would need to hook a function to wp_insert_comment and get the ID
of the comment. Then you could call wp_update_comment with your
changes to the dates and the ID and it would update the comment.

-Otto


More information about the wp-hackers mailing list