Как упорядочить кастомные посты?

Добрый день, перед мною стоит задача упорядочить кастомные записи кастомных категорий по количеству голосов пользователей. Для этого использую этот код:
<?php query_posts( array ( 'post_type' => 'servers', 'posts_per_page' => 10, 'meta_key' => 'ratings_users', 'orderby' => 'meta_value_num', 'order' => 'DESC', 'tax_query' => array(
		array(
			'taxonomy' => 'serverscat',
			'field'    => 'id',
			'terms'    => 'id'
		)
	),) ); while ( have_posts() ) : the_post(); ?>
		
		<?php
			/* Include the Post-Format-specific template for the content.
				* If you want to override this in a child theme, then include a file
				* called content-___.php (where ___ is the Post Format name) and that will be used instead.
			*/
			get_template_part( 'template-parts/content-servers', get_post_format() );
		?>
		
		<?php endwhile; ?>
		
		<?php // if WP version 4.1.0 or above use the_posts_pagination() built in function.
		if (4.1 <= floatval(get_bloginfo('version'))):?>                    
		<?php the_posts_pagination( array(
			'mid_size' => 1,
			'prev_text' => __( '&#8249; Предыдущая', 'mmogames' ),
			'next_text' => __( 'Следующая &#8250;', 'mmogames' ),
		) ); ?>
		<?php else : ?>
		<?php mmogames_pagination(); ?>
		<?php endif; ?>	

		<?php the_archive_description( '<div class="dseotxt">', '</div>' ); ?>
		
		<?php else : ?>	
		<?php get_template_part( 'template-parts/content', 'none' ); ?>		
		<?php endif; ?>


Проблема: - как в 'terms' => 'id' подставить id текущей кастомной категории.

Заранее спасибо за помощь.
  • Вопрос задан
  • 21 просмотр
Решения вопроса 1
@Gvynblade Автор вопроса
Нашел решение
<?php $queried_object = get_queried_object()->term_id;
 $servers1 = new WP_Query( array ( 'post_type' => 'servers', 'posts_per_page' => 10, 'meta_key' => 'ratings_users', 'orderby' => 'meta_value_num', 'order' => 'DESC', 'tax_query' => array(
		array(
			'taxonomy' => 'serverscat',
			'field'    => 'id',
			'terms'    => $queried_object
		)
	),) ); if ( $servers1->have_posts() ) : ?>

<?php while ( $servers1->have_posts() ) : $servers1->the_post(); ?>
		
		<?php
			/* Include the Post-Format-specific template for the content.
				* If you want to override this in a child theme, then include a file
				* called content-___.php (where ___ is the Post Format name) and that will be used instead.
			*/
			get_template_part( 'template-parts/content-servers', get_post_format() );
		?>
		
		<?php endwhile; ?>
Ответ написан
Комментировать
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы