Home Forums General Issues Loop through all posts, display if field = x


Loop through all posts, display if field = x

  • I am a bit of a beginner to WP and ACF. I want to have a post (with custom PHP) that pulls all post title/URLs to posts that have X custom field value.

    I assume I would loop through all posts in my blog? Then get the post title for the URL text, and build the URL via the post permalink (better than ID URL for SEO).

    Any general tips on approach? Which functions I should be using? Etc.

  • A few tips:

    In the future, if your topic is a question, please do not mark it as a post. Can you please edit this topic and set it as a question so it can be marked solved once complete.

    I would use the get_posts function which accepts the WP_Query args to find the posts. There are args that allow you to search for custom field values. There is even documentation on the ACF site that talks you through how to query posts based on custom field values.

    On that note, did you not search before posting this question?

  • This is exactly what I had wanted to know for a long time. Thanks you for your share..

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

The topic ‘Loop through all posts, display if field = x’ is closed to new replies.