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 !
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?$_POST['comment_section']
variable when trying to make a comment via reply, and the return value ofadd_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.