@zeni1agent

Как мне сделать сообщение «Нечего не найдено»?

Я использую wp_query
<?php
$custom_query = new WP_Query( $args );
if ( $custom_query->have_posts() ) { 
  while( $custom_query->have_posts() ) {	$custom_query->the_post();
?>
<div>News</div>
 <?php
 }
 if ($custom_query->max_num_pages > 1) {  
      $orig_query = $wp_query;
      $wp_query = $custom_query;
  the_posts_pagination(array(	  
 		'show_all'     => true
      ));   
	$wp_query = $orig_query;  
  }
  wp_reset_postdata();  
 } ?>

И я бы хотел узнать могу ли я как то вывести сообщение "Нечего не найдено" в случае если WP_Query не найдет посты
  • Вопрос задан
  • 15 просмотров
Решения вопроса 2
@Lord_Dantes
if ( $custom_query->have_posts() ) { 
  while( $custom_query->have_posts() ) {	$custom_query->the_post();
?>
<div>News</div>
 <?php
 } else {
echo "Ничего  не найдено"
}
Ответ написан
Комментировать
deniscopro
@deniscopro Куратор тега WordPress
WordPress-разработчик, denisco.pro
Так?
<?php
$custom_query = new WP_Query( $args );
if ( $custom_query->have_posts() ) {
	while ( $custom_query->have_posts() ) {
		$custom_query->the_post();
		?>
		<div>News</div>
		<?php
	}
	if ( $custom_query->max_num_pages > 1 ) {
		$orig_query = $wp_query;
		$wp_query = $custom_query;
		the_posts_pagination( array(
			'show_all' => true
		) );
		$wp_query = $orig_query;
	}
	wp_reset_postdata();
} else {
	echo 'Ничего не найдено';
}
?>
Ответ написан
Комментировать
Пригласить эксперта
Ваш ответ на вопрос

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

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