Home › Forums › General Issues › Count of posts with the same field choice › Reply To: Count of posts with the same field choice
Try this function: https://gist.github.com/wells5609/5944561
It counts posts of a given post type with either a meta_key, meta_value, or key/value pair. Results are cached for 3 hours (you can change this depending on how often the post count will change). Use in a template like:
$post_count = get_post_count_by_meta('some_key', 'some_value', 'some-post-type');
echo $post_count;
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.