I need to find if a post with a custom field X equal to Y exists in a wordpress installation.
Should I do it with a simple sql query or is there something build in that can help me achieve it?
|
|
You can use the WP_Query(); to check that like this:
Hope this helps |
|||||||||||
|
|
The current way would be something like this:
Just note that in upcoming 3.1 querying for custom fields is considerably improved and arguments change, see Custom Field Parameters in Codex. |
|||
|
|
If you want to use this externally(per your comments), to keep the operation cheap you could do something like this.
Loading Let me know if you need an example SQL query to fetch posts based on meta. |
|||
|