Özel bir yazı türü "işleri" toplam mesaj sayısını saymaya çalışıyorum. Gönderiler olduğunu bildiğimde sorgum "0" değerini döndürüyor. Gönderi türünün gönderileri olup olmadığını kontrol ettiğini düşünmüyorum, ama neden ... herhangi bir fikir?
<?php $jobs = new WP_Query(array( 'post_type' => 'jobs' ));?>
<?php if ($jobs->have_posts()) {
$count_posts = wp_count_posts()->publish;
if ( $count_posts == "1" ) {
echo "<h2>There is currently one vacancy...</h2>"; }
else { echo "<h2>There are currently $count_posts vacancies...</h2>"; }
} else { ?>
<h2>There are currently no vacancies.</h2>
<?php } ?>
Yan not olarak, yalnızca sorgunun orijinal sonuçlarını görmek için count ($ jobs) veya print_r ($ jobs) denediniz mi?
—
redconservatory
Hayır, sadece denedim ve yararlı bir şey yok.
—
Dan Lee