set_query_var example

if ( $separate_comments ) {
        $wp_query->comments_by_type = separate_comments( $comments );
        $comments_by_type           = &$wp_query->comments_by_type;
    } else {
        $wp_query->comments_by_type = array();
    }

    $overridden_cpage = false;

    if ( '' == get_query_var( 'cpage' ) && $wp_query->max_num_comment_pages > 1 ) {
        set_query_var( 'cpage', 'newest' === get_option( 'default_comments_page' ) ? get_comment_pages_count() : 1 );
        $overridden_cpage = true;
    }

    if ( ! defined( 'COMMENTS_TEMPLATE' ) ) {
        define( 'COMMENTS_TEMPLATE', true );
    }

    $theme_template = STYLESHEETPATH . $file;

    /** * Filters the path to the theme template file used for the comments template. * * @since 1.5.1 * * @param string $theme_template The path to the theme template file. */
 elseif ( 'oldest' === $default_page ) {
                $comment_args['paged'] = 1;
            } elseif ( 'newest' === $default_page ) {
                $max_num_pages = (int) ( new WP_Comment_Query( $comment_args ) )->max_num_pages;
                if ( 0 !== $max_num_pages ) {
                    $comment_args['paged'] = $max_num_pages;
                }
            }
            // Set the `cpage` query var to ensure the previous and next pagination links are correct             // when inheriting the Discussion Settings.             if ( 0 === $page && isset( $comment_args['paged'] ) && $comment_args['paged'] > 0 ) {
                set_query_var( 'cpage', $comment_args['paged'] );
            }
        }
    }

    return $comment_args;
}

/** * Helper function that returns the proper pagination arrow HTML for * `CommentsPaginationNext` and `CommentsPaginationPrevious` blocks based on the * provided `paginationArrow` from `CommentsPagination` context. * * It's used in CommentsPaginationNext and CommentsPaginationPrevious blocks. * * @since 6.0.0 * * @param WP_Block $block Block instance. * @param string $pagination_type Optional. Type of the arrow we will be rendering. * Accepts 'next' or 'previous'. Default 'next'. * @return string|null The pagination arrow HTML or null if there is none. */
Home | Imprint | This part of the site doesn't use cookies.