我以前从未弄乱过评论循环,但我正在尝试一些东西。基本上,我在弹出式iframe中有我的注释表单,这是一个ajax操作,用于处理表单提交、插入注释和更新注释列表。
不过,我在页面上第二次运行注释循环时遇到问题。注释表单可以正常运行,但注释不会显示在Ajax刷新中。have_comments()
结果为false,并且wp_list_comments()
无输出。
你知道怎么了吗?
这是我的Ajax处理程序,以防出现问题:
/* Submit Comments Through AJAX */
add_action ( \'wp_ajax_submit_comment\', \'ajax_insert_comment\' );
add_action ( \'wp_ajax_nopriv_submit_comment\', \'ajax_insert_comment\' );
function ajax_insert_comment() {
/* obviously all of this needs sanitization,
its oversimplified, just to get the idea across */
$data = extract( wp_parse_args( $_POST ) );
$current_user = wp_get_current_user();
$comment = wp_insert_comment( array(
\'user_id\' => $current_user->ID,
\'comment_author\' => $current_user->display_name,
\'comment_author_email\' => $current_user->user_email,
\'comment_post_ID\' => intval( $comment_post_ID ),
\'comment_parent\' => intval( $comment_parent ),
\'comment_content\' => $comment,
\'comment_type\' => $comment_type
) );
wp_reset_query();
global $post; $wp_the_query;
$post = get_post( $comment_post_ID );
setup_postdata( $post );
/* Here\'s the problem: How to rewind the comments query
so that it will actually display comments. I\'ve tried
all of these things, but they\'re not working right now */
$wp_query->current_comment = -1;
$wp_query->rewind_comments();
// send comments list again.
include( get_stylesheet_directory(). \'/comments.php\' );
die(0);
}
回调只接受Ajax响应并用结果更新comments div。但它缺少整个评论列表。你知道我需要调用什么来回放评论循环并使其实际显示吗?