Saya mencoba menghitung jumlah total postingan dari jenis "custom" posting kustom. Permintaan saya hanya mengembalikan "0" ketika saya tahu ada posting. Saya tidak berpikir itu memeriksa bahwa jenis posting memiliki posting, tapi saya tidak mengerti mengapa ... ada ide?
<?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 } ?>
Sebagai catatan tambahan, apakah Anda mencoba menghitung ($ jobs) atau print_r ($ jobs) hanya untuk melihat hasil asli dari kueri?
—
redconservatory
tidak, coba saja dan itu tidak berguna.
—
Dan Lee