Skip Navigation

[Resolved] Displaying total of Custom Type posts

This support ticket is created 6 years ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 -
- 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 -

Supporter timezone: Europe/London (GMT+00:00)

This topic contains 5 replies, has 2 voices.

Last updated by Richard Healey 6 years ago.

Assisted by: Nigel.

Author
Posts
#1199695

Tell us what you are trying to do?

I would like to create a shortcode to display the total of each of my custom type posts on the front page of my site - eg film reviews, messages, ebooks....

Is there any documentation that you are following?
https://toolset.com/forums/topic/show-at-total-post-count-for-custom-post-type/

Is there a similar example that we can see?
I used this code:

// Get post count for films
add_shortcode('filmcount', 'film_count');
function post_count() {
$count_posts = wp_count_posts('film');
$published_posts = $count_posts->publish;
return $published_posts . ' ';
}

What is the link to your site?
rmh.id.au

#1199771

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

If you are writing custom shortcodes for this it really is a generic WordPress question that would be better posted on stack exchange.

You can do the same without shortcodes by creating a View for a post type such as 'film', and in the Loop Output section between the wpv-loop tags output the shortcode wpv-found-count which will display the number of posts published of that type.

You would probably want to output zero in the no-items-found section, and also check the option "Disable the wrapping DIV around the View" to output the clean post count without additional markup.

#1199859

Hi, I have created a new View, but cannot get it to generate meaningful output - namely the total number of items. I can get the equivalent of a tag count cloud, but not the total. I do not have an account on Stack Exchange, and they are not allowing new account creation. Sorry. If this is not possible, I can reedit the home page every time I add new items, but that is very tedious. Probably less so than pursuing this?!

#1199878

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

Sorry, I spoke a bit too soon, you of course shouldn't output the shortcode withing the loop as it will output it multiple times, you just want to output it once, so just inside the wpv-items-found section but not within the wpv-loop tags.

Like this (tidying up the whitespace a little):

[wpv-layout-start]
	[wpv-items-found]
	[wpv-found-count]
	<!-- wpv-loop-start -->
		<wpv-loop></wpv-loop>
	<!-- wpv-loop-end -->
	[/wpv-items-found]
	[wpv-no-items-found]0[/wpv-no-items-found]
[wpv-layout-end]
#1200318
Clipboard01.jpg

My issue is resolved now. Thank you!
Although adding the ability to show the totals to the public could be added as a feature request - something like the (edited) information displayed in the At a Glance widget by typewheel.xyz (Glance That)

#1200323

My issue is resolved now. Thank you!