In the previous articles, we’ve known about what Custom Fields is and the application of custom fields which allows users to add arbitrary information into posts. But what do you do after that? In the recent post, you also learned how to add custom fields programmatically and display them in your theme. But you’ll see a shortcoming if there is no classification and searching. This post will guide you on how to get posts by custom fields in WordPress and we’ll create an interesting application: advanced search.
- Get Posts by Custom Fields in WordPress – Part 1
- How to Get Posts by Custom Fields in WordPress – Part 2
In part 1 of this series, we learned about how to get posts by custom fields in WordPress with the
WP_Query function. However, if we need to deal with databases, it’s better to find another faster, easier, and more convenient way. That method is joining
wp_postmeta tables together, and then querying by SQL. In part 2 of the series “How to get posts by custom fields in WordPress”, we’ll use this way to add the advanced searching feature that allows users to search by keywords in posts / pages titles and custom fields content.