Home › Forums › General Issues › Count completed custom post types by a particular field. › Reply To: Count completed custom post types by a particular field.
There’s a missing comma in the code I provided. I don’t always test all the code I post because it’s meant as an example, sometimes typos slip in. I generally assume that most people can do basic code debugging.
$args = array(
'post_type' => 'your-post-type',
'post_per_page' => -1, // get them all
'post_status' => 'publish', // or whatever status your looking for
'meta_query' => array(
array(
'key' => 'your-field-name',
'compare' => 'EXISTS'
)
)
)
$query = new WP_Query($args);
$post_count = count($query->posts);
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.