Filtering loop based on post custom field

Hi everyone,

Apologies if this has been answered - I have not been able to find a similar topic. I would like to set up the following loop and am hoping it is possible.

  1. We have a custom post type called “User Profile” which contains ACFs.
  2. Every user has the ability to create another custom post type called “Listings”.
  3. I would like to create a loop to be displayed on the “User Profile” CPT which lists the “Listings” (pun unintended) the particular user has created.

I have gut feeling this is doable but I am unsure how to set it up or which loop type I should use. Thanks in advance.


Hello! How is the User Profile CPT associated with the Listings CPT? Is the user submitting the listing being set as the author? Is the User Profile CPT associated with the WP user in any way?

This should be possible, assuming you’ve got the right relationships set up, but it will be difficult to help without a bit more context about where the relationship information is coming from :slight_smile:

Hi @julia

Thanks for replying.

Every CPT created by a user has their username stored within an ACF per post, and yes, the user will be the author for all of the above CPTs.

Alright, so then the user authors a User Profile and potentially Multiple Listing pages. On the User Profile page, we want a loop of Listings created by the author of the current page. Here’s what I would do (remember to update the listing_cpt_slug with your actual post type slug):

  <Loop type=listing_cpt_slug author="{Field author_id}">
    <li><a href="{Field url}"><Field title /></a></li>

I’ve tested it locally with posts, and it seems to work fine. Let me know if it works for you :slight_smile:

1 Like


Thanks heaps! That works like a treat. :+1:

Happy days. :slightly_smiling_face:

1 Like