The effects of alcohol on sustanon 250 leucine for – real weight loss & bodybuilding benefits?
Call comments_templ...
 
Share:
Notifications
Clear all

Call comments_template() after page is loaded

7 Posts
2 Users
3 Reactions
1,227 Views
Posts: 7
Topic starter
(@kingstakh)
Active Member
Joined: 4 years ago

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
Asti
Posts: 7617
 Asti
Support
(@asti)
Illustrious Member
Joined: 7 years ago

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. 

Reply
Posts: 7
Topic starter
(@kingstakh)
Active Member
Joined: 4 years ago

 

defaultform

Now rendered default Wordpress form

Posted by: @asti

If you create a global $post object correctly, it should work fine.

What is mean?

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

Illustrious Member
Posts: 7617

@kingstakh,

Please wait a bit. You'll be answered soon. The developers will try to modify the code and help you with this. 

Reply
Asti
 Asti
Support
(@asti)
Joined: 7 years ago

Illustrious Member
Posts: 7617

@kingstakh,

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. 

Reply
(@kingstakh)
Joined: 4 years ago

Active Member
Posts: 7

@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.

diplaynone

 

Reply
Asti
 Asti
Support
(@asti)
Joined: 7 years ago

Illustrious Member
Posts: 7617

@kingstakh,

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. 

Reply
Share: