WordPress.org

Ready to get started?Download WordPress

Forums

Comment form - choosing a post to comment from a list (2 posts)

  1. abrucius
    Member
    Posted 2 years ago #

    Hi

    If you comment on a post, by default your comment is hooked to that post. Would it be possible to add a dropdown list of all posts to the comment form and than pick a post to hook the comment to?

  2. bcworkz
    Member
    Posted 2 years ago #

    It's possible. There's probably a number of approaches. They all would involve doing a query to build the dropdown and add it to the comment form. The list can get very long, so you might limit it to the x latest posts. When building the list, don't forget to filter for only posts for which comments are open.

    The approach I would try first is to use javascript to alter the hidden comment form field which contains the post ID on the dropdown change event. Not sure how the redirect to show the new comment would work, but it's something to try.

    Another approach would be to find an appropriate hook in WP where you can swap in the altered post ID. You'd have to find where the $_POST['comment_post_ID'] gets assigned to the data which is then inserted into the DB. Hopefully there's a hook after this and before the comment is actually inserted. Even if the comment is inserted, you could always change the data in the DB after the fact.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.