1285
1285
'order' => 'ASC',
1286
1286
'status' => 'approve',
1287
1287
'post_id' => $post->ID,
1288
'hierarchical' => 'threaded',
1289
1288
'no_found_rows' => false,
1290
1289
'update_comment_meta_cache' => false, // We lazy-load comment meta for performance.
1292
if ( get_option('thread_comments') ) {
1293
$comment_args['hierarchical'] = 'threaded';
1295
$comment_args['hierarchical'] = false;
1293
1298
if ( $user_ID ) {
1294
1299
$comment_args['include_unapproved'] = array( $user_ID );
1295
1300
} elseif ( ! empty( $comment_author_email ) ) {
1335
1343
$_comments = $comment_query->comments;
1337
1345
// Trees must be flattened before they're passed to the walker.
1338
$comments_flat = array();
1339
foreach ( $_comments as $_comment ) {
1340
$comments_flat[] = $_comment;
1341
$comment_children = $_comment->get_children( array(
1343
'status' => $comment_args['status'],
1344
'orderby' => $comment_args['orderby']
1346
if ( $comment_args['hierarchical'] ) {
1347
$comments_flat = array();
1348
foreach ( $_comments as $_comment ) {
1349
$comments_flat[] = $_comment;
1350
$comment_children = $_comment->get_children( array(
1352
'status' => $comment_args['status'],
1353
'orderby' => $comment_args['orderby']
1347
foreach ( $comment_children as $comment_child ) {
1348
$comments_flat[] = $comment_child;
1356
foreach ( $comment_children as $comment_child ) {
1357
$comments_flat[] = $comment_child;
1361
$comments_flat = $_comments;
1926
1938
$r = apply_filters( 'wp_list_comments_args', $r );
1929
* If 'page' or 'per_page' has been passed, and does not match what's in $wp_query,
1930
* perform a separate comment query and allow Walker_Comment to paginate.
1932
if ( is_singular() && ( $r['page'] || $r['per_page'] ) ) {
1933
$current_cpage = get_query_var( 'cpage' );
1934
if ( ! $current_cpage ) {
1935
$current_cpage = 'newest' === get_option( 'default_comments_page' ) ? 1 : $wp_query->max_num_comment_pages;
1938
$current_per_page = get_query_var( 'comments_per_page' );
1939
if ( $r['page'] != $current_cpage || $r['per_page'] != $current_per_page ) {
1940
$comments = get_comments( array(
1941
'post_id' => get_queried_object_id(),
1942
'orderby' => 'comment_date_gmt',
1949
1940
// Figure out what comments we'll be looping through ($_comments)
1950
1941
if ( null !== $comments ) {
1951
1942
$comments = (array) $comments;
1960
1951
$_comments = $comments;
1963
if ( empty($wp_query->comments) )
1965
if ( 'all' != $r['type'] ) {
1966
if ( empty($wp_query->comments_by_type) )
1967
$wp_query->comments_by_type = separate_comments($wp_query->comments);
1968
if ( empty($wp_query->comments_by_type[$r['type']]) )
1955
* If 'page' or 'per_page' has been passed, and does not match what's in $wp_query,
1956
* perform a separate comment query and allow Walker_Comment to paginate.
1958
if ( $r['page'] || $r['per_page'] ) {
1959
$current_cpage = get_query_var( 'cpage' );
1960
if ( ! $current_cpage ) {
1961
$current_cpage = 'newest' === get_option( 'default_comments_page' ) ? 1 : $wp_query->max_num_comment_pages;
1964
$current_per_page = get_query_var( 'comments_per_page' );
1965
if ( $r['page'] != $current_cpage || $r['per_page'] != $current_per_page ) {
1967
$comments = get_comments( array(
1968
'post_id' => get_the_ID(),
1969
'orderby' => 'comment_date_gmt',
1974
if ( 'all' != $r['type'] ) {
1975
$comments_by_type = separate_comments( $comments );
1976
if ( empty( $comments_by_type[ $r['type'] ] ) ) {
1980
$_comments = $comments_by_type[ $r['type'] ];
1982
$_comments = $comments;
1986
// Otherwise, fall back on the comments from `$wp_query->comments`.
1988
if ( empty($wp_query->comments) )
1970
$_comments = $wp_query->comments_by_type[$r['type']];
1972
$_comments = $wp_query->comments;
1975
// Pagination is already handled by `WP_Comment_Query`, so we tell Walker not to bother.
1976
if ( $wp_query->max_num_comment_pages ) {
1977
$default_comments_page = get_option( 'default_comments_page' );
1978
$cpage = get_query_var( 'cpage' );
1979
if ( 'newest' === $default_comments_page ) {
1980
$r['cpage'] = $cpage;
1982
// When first page shows oldest comments, post permalink is the same as the comment permalink.
1983
} elseif ( $cpage == 1 ) {
1990
if ( 'all' != $r['type'] ) {
1991
if ( empty($wp_query->comments_by_type) )
1992
$wp_query->comments_by_type = separate_comments($wp_query->comments);
1993
if ( empty($wp_query->comments_by_type[$r['type']]) )
1995
$_comments = $wp_query->comments_by_type[$r['type']];
1986
$r['cpage'] = $cpage;
1997
$_comments = $wp_query->comments;
2000
if ( $wp_query->max_num_comment_pages ) {
2001
$default_comments_page = get_option( 'default_comments_page' );
2002
$cpage = get_query_var( 'cpage' );
2003
if ( 'newest' === $default_comments_page ) {
2004
$r['cpage'] = $cpage;
2007
* When first page shows oldest comments, post permalink is the same as
2008
* the comment permalink.
2010
} elseif ( $cpage == 1 ) {
2013
$r['cpage'] = $cpage;