Support

Account

Home Forums General Issues Counting ACF fields with values

Helping

Counting ACF fields with values

  • Found this thread: https://support.advancedcustomfields.com/forums/topic/count-custom-fields-with-specific-value/

    But this works when the field type returns a specific value. How do we count when the field type has multiple selections, and we want to specify one of those selections?

    Secondly, the count of *all* posts of a certain post type?

    Thanks for any pointers. I don’t mind writing raw SQL if needed, because that’ll give us more control. Our templates are cached, so query speed is not an issue either. We just need to know how to join the appropriate tables so we get the meta values.

  • I wouldn’t be able to give you sql for this. If a field can have different values the only way that I can think of to count each of the possible values is to

    1) Do a query for all posts of the post type
    2) Loop over each post
    3) Get the field for each post
    4) Loop over the values and count the ones that are selected

Viewing 2 posts - 1 through 2 (of 2 total)

The topic ‘Counting ACF fields with values’ is closed to new replies.