Notifications
Clear all

Hook for saving meta/custom field to comment (not wpDiscuz form/custom fields)

12 Posts
4 Users
0 Likes
4,579 Views
(@gravityswitch)
Member Customer
Joined: 8 years ago
Posts: 6
Topic starter  

Hello,

A site we manage uses wpDiscuz for comments but we need to expose a custom field that was designed in ACF (Advanced Custom Fields). The form data uses WP core tags and the saved data needs to integrate with ordinary WP queries so we cannot use the wpDiscuz custom fields alone. We have successfully inserted the ACF field as a field inside the form with the "wc_main_comm_form" class via Javascript. However, we cannot figure out how to access and save the meta data once the form has been submitted via AJAX. Is there any hook from which we can intercept the raw form data and associate our custom field to the comment once it has an ID or ensure it is included with the correct key name in the meta data wpDiscuz saves?


   
Quote
 Tom
(@tomson)
Famed Member Admin
Joined: 9 years ago
Posts: 4172
 

Hi  Jessa,

I'm sorry but there s no way to complete this kind of integration. wpDiscuz comes with own custom fields and forms, it's not designed to integrate with ACF fields.


   
ReplyQuote
(@gravityswitch)
Member Customer
Joined: 8 years ago
Posts: 6
Topic starter  

If there is no hook to process fields unrelated wpDiscuz, is there any way to query wpDiscuz custom fields without resorting to raw SQL (or with, if need be)? For example, how can we find all comments with a custom field matching a given value in the Wordpress template?


   
ReplyQuote
 Tom
(@tomson)
Famed Member Admin
Joined: 9 years ago
Posts: 4172
 

This is all custom codding and custom SQL queries. All meta data of comments are stored in wp_commentmeta table. You should use this table.


   
ReplyQuote
(@keerthi92)
Active Member
Joined: 6 years ago
Posts: 10
 

Hi

I have created a new plugin. In that i have multiple parameter and i have passed as hidden field.I want to save that when comments are posted. Is there any hook available in wpdiscuz for saving custom fields.

 

 


   
ReplyQuote
Astghik
(@astgh)
Illustrious Member Admin
Joined: 6 years ago
Posts: 5912
 

Hi @keerthi92,

WordPress has such a hook for this purpose. 

https://codex.wordpress.org/Plugin_API/Action_Reference/comment_post


   
ReplyQuote
(@keerthi92)
Active Member
Joined: 6 years ago
Posts: 10
 

Hi @astghik

Thanks for your reply.But this is not what i want.

I want to save meta key value.So i used the following hook in my function.php

function save_comment_meta_data( $comment_id ) {
add_comment_meta( $comment_id, 'contest_id', $_GET[ 'id' ] );
}
add_action( 'comment_post', 'save_comment_meta_data' );

 

I have installed wpdiscuz plugin.When i post my comment, the above meta key is entered with null value.I don't know why.But if i uninstall the wpdiscuz plugin the value is saved correctly.

Can you please suggest me how to insert metakey when i post comment through wpdiscuz plugin

 

Thank you


   
ReplyQuote
Astghik
(@astgh)
Illustrious Member Admin
Joined: 6 years ago
Posts: 5912
 

Ho @keerthi92,

you need to use the code like this one. 

add_action( 'wpdiscuz_comment_post', 'save_comment_meta_data' );

function save_comment_meta_data( $messageArray ) {
if (isset($messageArray['new_comment_id']) && ($comment_id = intval($messageArray['new_comment_id'])) && isset($messageArray['contest_id']) && ($contest_id = intval($messageArray['contest_id'])))
add_comment_meta( $comment_id, 'contest_id', $contest_id );
}

   
ReplyQuote
(@keerthi92)
Active Member
Joined: 6 years ago
Posts: 10
 

How to add hidden fields in wpdiscuz


   
ReplyQuote
Astghik
(@astgh)
Illustrious Member Admin
Joined: 6 years ago
Posts: 5912
 

Hi keerthi92,

I'm sorry but I don't follow you. Could you please clarify a bit? 


   
ReplyQuote
(@keerthi92)
Active Member
Joined: 6 years ago
Posts: 10
 

Hi

Can You please tell me how to add hidden fields after form field in wpdiscuz


   
ReplyQuote
 Tom
(@tomson)
Famed Member Admin
Joined: 9 years ago
Posts: 4172
 

I'm sorry but there is no way to add hidden field in comment form. The only way is adding a simple text field using wpDiscuz comment form builder, then hide it using CSS code.

Managing comment form fields: https://wpdiscuz.com/docs/wpdiscuz-documentation/getting-started/custom-comment-form/comment-form-builder/


   
ReplyQuote
Share:
Scroll to top