Title: Comments on wrong post
Last modified: September 1, 2016

---

# Comments on wrong post

 *  Resolved [Moshe Harush](https://wordpress.org/support/users/localghost-il/)
 * (@localghost-il)
 * [9 years, 9 months ago](https://wordpress.org/support/topic/comments-on-wrong-post/)
 * Hey,
    I have a one page with posts loop. When user click on the post it is toggle
   the content.
 * The problem was the comment insert to another post,
    I try to change the value
   of js obj: wpdiscuzAjaxObj.wpdiscuz_options.wc_post_id
 * But the form still send another post id in form data.
 * can are u fix that or just tell me where is the variable to change for control
   the post id of comment sent?
 * Thanks!
 * [https://wordpress.org/plugins/wpdiscuz/](https://wordpress.org/plugins/wpdiscuz/)

Viewing 9 replies - 1 through 9 (of 9 total)

 *  Plugin Author [gVectors Team](https://wordpress.org/support/users/gvectors-team/)
 * (@gvectors-team)
 * [9 years, 9 months ago](https://wordpress.org/support/topic/comments-on-wrong-post/#post-7669646)
 * Hi LocalGhost-IL,
    I’m sorry but I didn’t follow you. Could you please explain
   it again? Do you mean comment are being attached to wrong posts? If so please
   check if you have Jetpack Comments. You should not use Jetpack comment with wpDiscuz.
 *  Thread Starter [Moshe Harush](https://wordpress.org/support/users/localghost-il/)
 * (@localghost-il)
 * [9 years, 9 months ago](https://wordpress.org/support/topic/comments-on-wrong-post/#post-7669649)
 * Hi,
    Thank you for replay.
 * I am not use Jetpack comments.
 * I have many posts on one page with ajax.
    Per post I have ajax button “Show comments”,
   On click its call to admin ajax and return this:
 *     ```
       function getPostComments() {
       			$ID = $_POST["post_id"];
   
       			query_posts( array( 'p' => $ID ) );
       			if ( have_posts() ) {
       				while( have_posts() ) {
       					the_post();
       					comments_template();
                 echo '<script> FB.XFBML.parse(); </script>'; // For parse facebook comments xfbml to html
       					die();
       				}
       			}
       			exit;
       }
       ```
   
 * The problem is when user leave a comment its commented on another posts.
 *  Plugin Author [gVectors Team](https://wordpress.org/support/users/gvectors-team/)
 * (@gvectors-team)
 * [9 years, 9 months ago](https://wordpress.org/support/topic/comments-on-wrong-post/#post-7669651)
 * What plugin does this? Have you checked this problem without they extra ajax 
   buttons and functions?
 *  Thread Starter [Moshe Harush](https://wordpress.org/support/users/localghost-il/)
 * (@localghost-il)
 * [9 years, 9 months ago](https://wordpress.org/support/topic/comments-on-wrong-post/#post-7669655)
 * The plugin will work without the ajax.
    But the problem its on how your plugin
   work. He take post id for the comment from some where and not use the form of
   comments.
 *  [Aghasi](https://wordpress.org/support/users/aghasi/)
 * (@aghasi)
 * [9 years, 9 months ago](https://wordpress.org/support/topic/comments-on-wrong-post/#post-7669712)
 * Hi LocalGhost-IL,
    once you submit the comment, in the request you should check
   what is post id? if that is the post id you need that is fine, if not, our plugin
   is open source and you can check from there too.
 *  Thread Starter [Moshe Harush](https://wordpress.org/support/users/localghost-il/)
 * (@localghost-il)
 * [9 years, 9 months ago](https://wordpress.org/support/topic/comments-on-wrong-post/#post-7669726)
 * The post id its of another post on page,
    Not the post I will commented on him.
 * So This is your github repo?
    [https://github.com/wp-plugins/wpdiscuz](https://github.com/wp-plugins/wpdiscuz)
 * Can you show me the appropriate line in the code that pulls out the post id?
 *  Thread Starter [Moshe Harush](https://wordpress.org/support/users/localghost-il/)
 * (@localghost-il)
 * [9 years, 9 months ago](https://wordpress.org/support/topic/comments-on-wrong-post/#post-7669736)
 * The problem is here:
 *     ```
       /**
            * @param {type} action the action key
            * @param {type} data the request properties
            * @returns {jqXHR}
            */
           function getAjaxObj(data) {
               if (data.action !== 'liveUpdate') {
                   $('.wpdiscuz-loading-bar').show();
               }
               data.append('postId', wpdiscuzPostId);
               return $.ajax({
                   type: 'POST',
                   url: wpdiscuzAjaxObj.url,
                   data: data,
                   contentType: false,
                   processData: false,
               });
           }
       ```
   
 * The var wpdiscuzPostId set in like this:
 *     ```
       var wpdiscuzPostId = wpdiscuzAjaxObj.wpdiscuz_options.wc_post_id;
       ```
   
 * But if I use on one page more then one post with comments the global object wpdiscuzAjaxObj
   can be used.
    All case this way is bad practice, why not add a input hidden name
   =post_id in the comment form? why use base on js var?
 *  [Aghasi](https://wordpress.org/support/users/aghasi/)
 * (@aghasi)
 * [9 years, 9 months ago](https://wordpress.org/support/topic/comments-on-wrong-post/#post-7669761)
 * Please note: so, if you mean that e.g. you have one page, and 2 or more posts,
   and you want to have 2 or more comment forms under those posts, it won’t work.
 *  Thread Starter [Moshe Harush](https://wordpress.org/support/users/localghost-il/)
 * (@localghost-il)
 * [9 years, 9 months ago](https://wordpress.org/support/topic/comments-on-wrong-post/#post-7669845)
 * I fix that with assign the wpdiscuzAjaxObj.wpdiscuz_options.wc_post_id var on
   post toggle in loop view.
 * And in the function getAjaxObj I change wpdiscuzPostId var to full source refernce
   var wpdiscuzAjaxObj.wpdiscuz_options.wc_post_id
 * Its work.
 * If u have a github repo I can send a commit as pull request.
    Please let me know.

Viewing 9 replies - 1 through 9 (of 9 total)

The topic ‘Comments on wrong post’ is closed to new replies.

 * ![](https://ps.w.org/wpdiscuz/assets/icon-256x256.png?rev=1076265)
 * [Comments - wpDiscuz](https://wordpress.org/plugins/wpdiscuz/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/wpdiscuz/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/wpdiscuz/)
 * [Active Topics](https://wordpress.org/support/plugin/wpdiscuz/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/wpdiscuz/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/wpdiscuz/reviews/)

## Tags

 * [ajax comment](https://wordpress.org/support/topic-tag/ajax-comment/)
 * [js](https://wordpress.org/support/topic-tag/js/)

 * 9 replies
 * 3 participants
 * Last reply from: [Moshe Harush](https://wordpress.org/support/users/localghost-il/)
 * Last activity: [9 years, 9 months ago](https://wordpress.org/support/topic/comments-on-wrong-post/#post-7669845)
 * Status: resolved