Join the Voxel Guide Community!

Get Involved

Count total posts and display with shortcode

Description/Instructions

Until an official mod will be released you can use this php snippet to display total posts of a post type with an elementor shortcode widget.

Search through [total_places] places

Instructions

Use shortcodes like [total_places], [total_events], etc.

Duplicate snippet and change post type slug.

// Get total places
add_shortcode('total_places', 'count_places');
function count_places() {
$count_posts = wp_count_posts('places');
$published_posts = $count_posts->publish;
return $published_posts . '' . '';
}

// Get total events
add_shortcode('total_events', 'count_events');
function count_events() {
$count_posts = wp_count_posts('events');
$published_posts = $count_posts->publish;
return $published_posts . '' . '';
}

  • PHP
Copy Code

Let's Chat About this Snippet

Chat Toggle
Voxel Guide AI
Voxel Guide AI
Voxel Guide AI
Voxel Guide AI
Ask me anything about Voxel!
Send
Powered by AI24