Amit

How to display the total number of posts per page for custom post types in WordPress.

If you want to create custom query for showing Total WordPress posts per page. you can use below code.

<?php 
$paged = ( get_query_var('page') ) ? get_query_var('page') : 1;

global $wp_query;
global $paged;

if (empty($paged)) {
	$paged = 1;
}

//Get post per page number. it's coming from Reading Settings -> Blog pages show at most.

$ppp = get_query_var('posts_per_page');

$end = $ppp * $paged;
$start = $end - $ppp + 1;
$post_count = wp_count_posts('post-type-name');  //Add your CPT name
$total_posts = $post_count->publish;

// get last page post number
$last_page_post = ( $total_posts - ( $ppp * ($paged - 1 ) ));
$last_post_count = $start + $last_page_post -1;

//count number of page
$page_number_max = ceil($total_posts / $ppp);

?>

<p>Page <?php echo $paged; ?> Showing <?php echo $start; ?> - <?php if($paged == $page_number_max ) { echo $last_post_count; } else { echo $end; } ?> out of <?php echo $total_posts;  ?> Total </p>

Last Update on:March 5th, 2023 at 5:19 pm


How to remove custom post type slug from wordpress
Previous post