'How to show WordPress comment form on ajax call result
I have this function which is call on Ajax Call:
function ticket_view_action() {
if ( ! wp_verify_nonce( $_POST['nonce'], 'ticket_view_action' ) ) {
return false;
}
if( ! is_user_logged_in() ) {
return false;
}
$ticket_id = (int) $_POST['ticket_id'];
$get_ticket = get_posts( array(
'post_type' => 'ticket',
'author' => get_current_user_id(),
'p' => $ticket_id
) );
if( $get_ticket ) {
echo "<div class='ticket-content post-box'>";
foreach( $get_ticket as $post ) {
setup_postdata( $post );
echo "<div class='entry-header'>";
echo "<div class='entry-meta'>";
echo "<span class='byline'>" . get_the_author_meta( 'display_name', $post->post_author ) . "</span>";
echo "<span class='posted-on'>" . ' On ' . $post->post_date . "</span>";
echo "</div>";
echo "<h4>". $post->post_title."</h4>";
echo '<hr/>';
echo "</div>";
echo nl2br( $post->post_content );
comments_template();
}
wp_reset_postdata();
echo "</div>";
} else {
echo 'No post found';
}
wp_die();
}
On that function, you can see that I have used comments_template(); function to show the comment form box but it's not showing.
How can I show the comment form?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
