Snippets / PHP
PHP
Count total posts and display with shortcode
G
Gabi Maftei
·
250 views
·
Updated 1 year ago
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
Search through [total_places] places
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 · 15 lines
Discussion
Ask a question or share how you used this.
Log in
to join the discussion.
No comments yet — be the first.