私はカスタムクエリで検索しているカスタムポストタイプを持っています。あまりにも多くの結果がある場合は、メッセージを出力したい(うまくいく)。しかし、私が持っている問題は、最初にページに行き、検索が実行されていないときです。私はそのメッセージを表示したくありません。検索が実行されていないときに表示を停止するにはどうすればよいですか?任意の検索語が現在のWP_Query
のために送られている場合はtrue検索が実行されたときにのみテキストを出力します
<?php if($the_query->post_count > 20 && is_search()) { ?>
is_search()
リターン:で
<?php if($the_query->post_count > 20) { ?>
:
<?php $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$args = array(
'posts_per_page' => 5,
'post_type' => 'researchdatabase',
'post_status' => 'publish',
'paged' => $paged
);
if($searchTerm != "") {
$args['s'] = $searchTerm;
}
$the_query = new WP_Query($args);
if ($the_query->have_posts()) {
$counter = 1; ?>
<p>
<b><?php echo $the_query->post_count; ?> research items</b>
<?php if($the_query->post_count > 20) { ?>
<br /><span class="research-alert"><b>Refine your search criteria to see fewer results.</b></span>
<?php } ?>
</p>
<hr />
<br />
<?php while ($the_query->have_posts()) { $the_query->the_post(); ?>
<?php // output results ?>
<?php $counter++;
} // end while
// reset post data
wp_reset_postdata();
} else {
echo 'No results';
} // end if
?>
「検索が行われていない場合」とは? –
@RazibAlMamun最初にページに上がったとき、検索フォームに記入されていないときに検索が押されなかったとき。 – Rob