Использование пользовательского цикла:
Если вы создаете пользовательский цикл, вы можете использовать WP_Query
.
<?php
$the_query = new WP_Query([
'order'=>'ASC'
]);
// The Loop
if ( $the_query->have_posts() ) :
while ( $the_query->have_posts() ) :
?>
<div class="postTitle"><?php the_title(); ?></div>
<div class="postContent"><?php the_content(); ?></div>
<?php
endwhile;
/* Restore original Post Data */
wp_reset_postdata();
?>
<?php else: ?>
// no posts found
<?php endif; ?>
Использование фильтров
Или другой метод состоит в том, чтобы изменить основной цикл, используя фильтры в файле functions.php
.
function alter_order_of_posts( $query ) {
if ( $query->is_main_query() ) {
$query->set( 'order', 'ASC' );
}
}
add_action( 'pre_get_posts', 'alter_order_of_posts' );
Я предлагаю путь фильтра, чтобы избежать изменения большого количества вашего текущего шаблона..