Support

Account

Home Forums ACF PRO Count how many posts are attached via Post Object

Solving

Count how many posts are attached via Post Object

  • So I’m setting up an internal system for our company to track stars/nominations. I’ve setup two CPT’s (‘User’ & ‘Nomination’).

    I’ve setup all team members under users with just their names as the title, then I can post nominations under the Nomination CPT, which I’ve setup two ACF fields using ‘Post Object’ which links to the users CPT. So I’m able to select a nominee and nominator.

    I want to create two front end pages, one that shows a loop of the nominations which is no problem. But also a page to display the users but also a number of stars which will be calculated by the amount of nominations they have which are set from the nominator ACF field for nominee.

    How can I go about getting a count of these which I can convert to a number and thus display against a star icon?

    I’d also like to create a single user page which displays the nominations given to them, again as above needing to display a nominations loop but only for that particular user.

  • you would need to do a reverse relationship query as explained here https://www.advancedcustomfields.com/resources/querying-relationship-fields/ with modification to the meta query that I explained here https://support.advancedcustomfields.com/forums/topic/querying-a-post-object-field-similarly-to-a-relationship-field/. Then count the number of posts returned.

  • Hi John, thanks for getting back to me.

    As mentioned in that guide, the locations are set to the doctor.

    I need to display my users (doctors) with the nominations though. Where the nomination post has the user assigned, not the user post with a nomination assigned. So how would I adapt the guide to what I need?

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

You must be logged in to reply to this topic.