how i can count from a custom post type the entries?
<ul class="test">
<?php $args = array( 'post_type' => 'schusslersalz', 'posts_per_page' => 30, 'orderby' => 'rand' );
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post();
echo '<li>';
the_title('<h3>', '</h3>');
the_content();
echo '</li>';
endwhile; ?>
</ul>
how can i count the entries from "schusslersalz" in a number and display it. I have serch and found the funciton:
$count = $loop->post_count;
how i use this?
The wp_count_posts
function has parameter $type
for post type to count, you should use this parameter if you want to count the number of schusslersalz
A snippet
$count_posts = wp_count_posts( 'schusslersalz' )->publish;
echo $count_posts;
Full snippet as follow:
$args = array(
'post_type' => 'schusslersalz'
);
$the_query = new WP_Query( $args );
echo $the_query->found_posts;
Hope I helped
Simple way to count total post including pagination post
<?php global $wp_query
$count = $wp_query->found_posts;
echo $count; ?>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With