<?php get_header(); ?>
<main id="content" class="content">
<?php do_action( 'basic_main_content_inner_begin' ); ?>
<?php if ( is_home() && 'customtitle' == get_theme_mod( 'home_h1_type', 'sitetitle' ) ) { ?>
<div class="blog-home-header">
<h1><?php echo esc_html( get_theme_mod( 'custom_home_h1', get_bloginfo('sitetitle') ) ); ?></h1>
</div>
<?php } ?>
<?php
$s1='';
$s2='';
$meta_key = '';
if (isset($_GET['order']) && $_GET['order'] == 'easiest') {
$order = "ASC";
$s1 = 'selected="selected"';
$meta_key = 'level';
}
if (isset($_GET['order']) && $_GET['order'] == 'hardest') {
$order = "DESC";
$s2 = 'selected="selected"';
$meta_key = 'level';
}
?>
<form method="get" style="margin-bottom: 20px;">
<select name="order" onchange="this.form.submit()">
<option value="0"><?php _e( 'Все записи', 'your_theme' ) ?></option>
<option value="easiest" <?php echo $s1?>><?php _e( 'Сначала простые', 'your_theme' ) ?></option>
<option value="hardest" <?php echo $s2?>><?php _e( 'Сначала сложные', 'your_theme' ) ?></option>
</select>
</form>
<?php
$current = absint( max( 1, get_query_var( 'paged' ) ? get_query_var( 'paged' ) : get_query_var( 'page' ) ) );
$posts_per_page = get_option( 'posts_per_page' );
$args = array(
'post_type' => 'post',
'posts_per_page' => $posts_per_page,
'paged' => $current,
'meta_key' => $meta_key,
'meta_value' => ' ',
'meta_compare' => '!=',
'orderby' => 'level',
'order' => $order,
);
$query = new WP_Query($args);
?>
<?php if( $query->have_posts() ) : ?>
<?php while( $query->have_posts() ) : $query->the_post(); ?>
<div>
<?php the_field('level') ?>
<?php get_template_part( 'content' ); ?>
</div>
<?php endwhile; ?>
<nav class="navigation pagination">
<div class="nav-links">
<?php
echo wp_kses_post(
paginate_links( [
'total' => $query->max_num_pages, // количество берем из дефолтной опции запроса
'current' => $current, // текущая страница
] )
);
?>
</div>
</nav>
<?php else: ?>
<div class="post clearfix">
<h2><?php _e( 'Posts not found', 'basic' ); ?></h2>
<?php get_search_form(); ?>
</div>
<?php endif; ?>
<?php wp_reset_query(); ?>
<?php do_action( 'basic_main_content_inner_end' ); ?>
</main>
<!-- END #content -->
<?php get_sidebar(); ?>
<?php get_footer(); ?>