How to Only Retrieve Posts With Custom Fields

Posted by admin in WordPress, HOW-TO, W... | 04.14.2008 - 6:00 am

One question I come across a lot regarding custom fields is how to only retrieve posts based on a custom field.
For example, if a post has a custom field of “MyData”, someone might want to only retrieve that particular post.
The WordPress Codex has a technique for retrieving posts based on custom fields, which consists of writing your own query and going through the results.
The technique in the Codex is good, but I’ve found a re-usable way one can retrieve only posts with certain custom fields.
The technique I use makes use of two custom functions placed in a theme’s “functions.php” and a custom WordPress Loop.
Let’s get started — The “functions.php” file
First, let’s place the two custom functions in the “functions.php” file. This file should be in your theme directory, but if it isn’t there, you can create one using any text editor.
Here are the two functions below:

function get_custom_field_posts_join($join) {
global $wpdb, […]

Original post by Ronald Huereca

    Technorati Tags:

    Related Posts:
  1. Custom Fields Made Easy
  2. ...
  3. Tutorial: Creating Custom Write Panels in WordPress
  4. ...
  5. Paging and Custom WordPress Loops
  6. ...
  7. Extending WordPress Beyond the Blog
  8. ...
  9. WordPress Plugin Releases for 10/26
  10. ...
  11. WordPress Theme Releases for 07/12
  12. ...
  13. WordPress Plugin Releases for 10/15
  14. ...
  15. WordPress As A CMS Checklist
  16. ...
  17. WordPress Theme Releases for 09/25
  18. ...
  19. Exporting-Importing A Category
  20. ...
  21. WordPress Theme Releases for 11/04
  22. ...
  23. Reformatting WordPress
  24. ...
  25. WordPress Hacks and Techniques List
  26. ...
  27. WP OpenAds
  28. ...
  29. Complete WordPress Theme Guide
  30. ...

  31. No Comments on "How to Only Retrieve Posts With Custom Fields" »

    No comments yet.

    Leave a comment