Dec 28, 2020 9:56 am
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>
6 Replies
Dec 28, 2020 11:55 am
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.
Dec 28, 2020 12:29 pm
Now rendered default Wordpress form
If you create a global $post object correctly, it should work fine.
What is mean?