Comments on wrong post
-
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.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.
What plugin does this? Have you checked this problem without they extra ajax buttons and functions?
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.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.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/wpdiscuzCan you show me the appropriate line in the code that pulls out the post id?
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?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.
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.
The topic ‘Comments on wrong post’ is closed to new replies.
(@localghost-il)
9 years, 9 months ago
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://ww.wp.xz.cn/plugins/wpdiscuz/