The effects of alcohol on sustanon 250 leucine for – real weight loss & bodybuilding benefits?
How to add wpdiscuz...
 
Share:
Notifications
Clear all

[Solved] How to add wpdiscuz_votes_separate when adding new comment

4 Posts
2 Users
2 Reactions
934 Views
Posts: 10
Topic starter
(@stevara)
Active Member
Joined: 3 years ago

I want to post a new comment from react native app using: POST /wp/v2/comments

When I add a comment like that, wpdiscuz_votes_separate and wpdiscuz_votes fields don't get created in commentmeta table at that point. They get created when I click on + or - on comment on the website. But I need it to be created immediately because I have to parse wpdiscuz_votes_separate value in order to show the the number of likes and dislikes, and also to be able to update them on the mobile app. I am updating them via endpoint in function.php file.

Can those rows be created with the creation of the comment somehow?

3 Replies
Posts: 10
Topic starter
(@stevara)
Active Member
Joined: 3 years ago

I handled it when posting new comment from my mobile app by adding 

add_action("rest_insert_comment", function ($comment, $request, $creating) {
    add_comment_meta($comment->comment_ID, 'wpdiscuz_votes_seperate', ["like" => 0, "dislike" => 0]);
    add_comment_meta($comment->comment_ID, 'wpdiscuz_votes', 0);
}, 10, 3);

to functions.php in my theme.

It adds these two fields to commentmeta table every time a new comment is created.

But it doesn't add these fields when I create a new comment on the website.

Can I add 

add_comment_meta($commentId, self::META_KEY_VOTES, 0);
add_comment_meta($commentId, self::META_KEY_VOTES_SEPARATE, ["like" => 0, "dislike" => 0]);

somewhere in addComment function in WpdiscuzCore.php ?

2 Replies
Asti
 Asti
Support
(@asti)
Joined: 7 years ago

Illustrious Member
Posts: 7661

@stevara,

The changes will be lost after the wpDiscuz updates.  

You can use the comment_post hook for this customization. More info here:

https://developer.wordpress.org/reference/hooks/comment_post/

We don't provide support for customization, we may help in 1-2 simple questions, but not more. We only help with general questions and issues.

Thank you for your understanding.

(@stevara)
Joined: 3 years ago

Active Member
Posts: 10

The solution that I came up with if there is no wpdiscuz_votes_seperate and wp_discuz_votes in the commentmeta table after the comment is added on the website and I try to like or dislike the comment on my mobile app:

When I try to select those fields from the commentmeta like I did here: https://wpdiscuz.com/community/postid/13043/

And the select returns nothing because there are no fields with those names I use the add_comment_meta instead of updating the database. Like this:

$result = $wpdb->get_results( "SELECT meta_value FROM $wpdb->commentmeta WHERE comment_id = $commentId AND meta_key = 'wpdiscuz_votes_seperate'")[0];
$meta = $result->{'meta_value'};
    
if($meta == ""){
    if(strcmp($voteType, 'like') === 0) {
        add_comment_meta($commentId, 'wpdiscuz_votes_seperate', ["like" => 1, "dislike" => 0]);
        add_comment_meta($commentId, 'wpdiscuz_votes', 1);
    }
    else {
        add_comment_meta($commentId, 'wpdiscuz_votes_seperate', ["like" => 0, "dislike" => 1]);
        add_comment_meta($commentId, 'wpdiscuz_votes', -1);
    }
}

Hope this helps anyone.

Share: