12% off of LTD using this coupon: TWELVEPERCENTOFF. Promo ends on 2 Dec midnight UTC.
Published on Dec 21, 2021

Getting count of posts for which User-type ACF field’s value matches the logged-in user

Sridhar Katakam

This members-only tutorial provides the steps to output the number of posts that have a User-type custom field's value i.e., a WordPress user matching with the currently logged-in user.

For example, let's say for a given post, the user (need not be the post author) has been set as User A:

Similarly, there are 3 other posts associated with User A.

With the code in this tutorial, we can show 4 (in the above example) on a Page titled say Profile or Dashboard on the front end when it is being viewed by the user, User A.

Each user will see the number of posts associated with them.

Visitors that are not logged in will see 0.

This tutorial complements the Filtering posts by comparing user email with User-type ACF field’s value in Oxygen article.

Step 1

Implement steps 1 to 3 of the earlier tutorial.

Step 2

Create a Page titled say, "Profile".

If using Oxygen, add a Section and inside that a Code Block having this code:

This is a premium members-only content.

To view the rest of the content, please sign up for membership ($47/month or $599 one-time).

Already a member? Log in below or here.