I try load comments_template() when page is fully loaded. But have default form loaded, how call wpdiscuz form?
My code functions.php
function comm(){
$p_id = ( $_POST['spd'] );
$args = array(
'posts_per_page' => -1,
'p' => $p_id
);
$yy_query = new WP_Query($args);
while ( $yy_query->have_posts() ) {
$yy_query->the_post();
global $withcomments;
$withcomments = true;
comments_template();
}
wp_die();
}
add_action('wp_ajax_mycomm', 'comm');
add_action('wp_ajax_nopriv_mycomm', 'comm');
Code single.php
<script>
var send_post_id = <?php the_ID(); ?>;
</script>
<div class="comment_template"></div>
And Ajax:
<script>
$(document).ready(function(){
$.ajax({
url: ajaxurl,
type: 'POST',
beforeSend: (function(){
$('.comment_template').html('Loading..');
}),
data: ({
action: 'mycomm',
spd: send_post_id
}),
success: function(data){
$('.comment_template').html(data);
}
})
});</script>
Hi @kingstakh,
If you create a global $post object correctly, it should work fine.
Also please don't duplicate the questions. Just open a new support topic here.
In case you want to say thank you! 🙂
We'd really appreciate if you leave a good review on the plugin page.
This is the best way to say thank you to this project and the support team.
Now rendered default Wordpress form
If you create a global $post object correctly, it should work fine.
What is mean?
Please wait a bit. You'll be answered soon. The developers will try to modify the code and help you with this.
In case you want to say thank you! 🙂
We'd really appreciate if you leave a good review on the plugin page.
This is the best way to say thank you to this project and the support team.
Below is provide the code. Use this one instead of the code you've put in the functions.php file.
function comm(){
$p_id = ( $_POST['spd'] );
$args = array(
'posts_per_page' => -1,
'p' => $p_id
);
$yy_query = new WP_Query($args);
while ( $yy_query->have_posts() ) {
$yy_query->the_post();
$wpdiscuz = wpDiscuz();
$wpdiscuz->form = $wpdiscuz->wpdiscuzForm->getForm(get_the_ID());
add_filter("comments_template", [&$wpdiscuz, "addCommentForm"], 9999999);
global $withcomments;
$withcomments = true;
comments_template();
}
wp_die();
}
add_action('wp_ajax_mycomm', 'comm');
add_action('wp_ajax_nopriv_mycomm', 'comm');
Please note if you use the code, the rich editor will not be loaded. So you will be able to use only the textarea.
In case you want to say thank you! 🙂
We'd really appreciate if you leave a good review on the plugin page.
This is the best way to say thank you to this project and the support team.
@asti thank you, now work nice. But have some little issue, when use Rich Editor in plugin setting form rendered with wpd-editor-wraper style display:none. Without Rich Editor all is ok.
Please note if you use the code, the rich editor will not be loaded. So you will be able to use only the textarea.
I've already mentioned this in my answer.
In case you want to say thank you! 🙂
We'd really appreciate if you leave a good review on the plugin page.
This is the best way to say thank you to this project and the support team.



