0

I need to add my custom meta to the new comments. Here is what I've done :

/************************************************************************/
/*  Add meta to comments
/************************************************************************/
// Save field
add_action ('comment_post', 'add_meta_settings', 1);

function add_meta_settings($comment_id) {
    add_comment_meta($comment_id, 'comment_section', $_POST['comment_section'], true);
}

This work when I create a new comment. But if I post a comment using the "Reply" (to another comment) link, the meta is not saved...

After further investigation :

On the same page, I have 3 comment threads. Each comment has a meta that tells in which tread they have to be displayed in. At the end of each thread, I have a form to post a comment in this specific thread and it adds the right meta.

The problem is when I click the “Reply” link, it adds a form under the comment, but not the good form. It adds the first form that appears in the page, event if I reply a comment from the third thread. So the meta that is added with my new comment is not the good one…

Is there a way to tell WordPress which form to use when I click the “Reply” link ?

Could you help me ?

Thanks !

  • 1
    add_comment_meta returns a true/false success value, but you're not checking this, can you find out what it returns when you attempt to reply? – Tom J Nowell May 7 '14 at 9:04
  • Hi @TomJNowell ! I've edited my question with further investigation :) ! Thanks – Cédric Charles May 7 '14 at 9:37
  • 1
    hmm I'm of the opinion we still require more technical information, such as the value of the $_POST['comment_section'] variable when trying to make a comment via reply, and the return value of add_comment_meta indicating true or false. I suspect it's because hitting reply sends via AJAX and you're trying to save an empty value, but without further information I cannot diagnose the issue further or verify this. – Tom J Nowell May 7 '14 at 9:59
  • If I inspect the html generated in the reply comment, the hidden field containing the value of "comment_section" has always the value of the meat of the first comment form appearing in the page : "comments". – Cédric Charles May 7 '14 at 10:04
  • hmmm but what do those variables I enquired about contain? If you don't know how to get that you can just ask =] – Tom J Nowell May 7 '14 at 10:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.