I would like to display some stats on my website. For multiple post types I would like something like this:
XXX Reviews (XX)
- where the first
XXX
is the total amount which I can get by usingwp_count_posts('reviews')
- where
Reviews
is the name of the posttype - where
(XX)
show how many reviews were added last month or week (still need to decide on that but idea is the same)
I'm only missing point 3, how do I do this most efficient, I know I can use get_posts()
and use dynamic vars to pull the data but I think is pretty resourceful right?
I need to do this for 4 post types on my home page, in the future, more might be added.
get_posts
is your answer. Add'fields' => 'ids'
to theget_posts
arguments, this way you get only the post ID's. This way you cut up to 99.9% on db queries and time :-) – Pieter Goosen Jul 10 '15 at 8:28