
January 6th, 2013, 12:39 AM
|
 |
Lost in code
|
|
|
|
You would use a left or inner join on it; the former for optional meta keys and the latter for required meta keys. For example:
Code:
SELECT
wp_posts.post_title,
post_type_meta.meta_value AS post_type_value,
mabp_description_meta.meta_value AS mabp_description_value
FROM wp_posts
LEFT JOIN wp_postmeta AS post_type_meta ON
post_type_meta.post_id = wp_posts.ID
AND post_type_meta.meta_key = 'post_type_value'
LEFT JOIN wp_postmeta AS mabp_description_meta ON
mabp_description_meta.post_id = wp_posts.ID
AND mabp_description_meta.meta_key = 'mabp_description'
WHERE wp_posts.ID = '$id'
However, note that:
* The mysql_* PHP library is deprecated and mysqli or PDO should be used instead.
* You don't need to call mysql_num_rows unless you're actually going to use the value.
* mysql_close closes the connection to the MySQL server, which is not what you want to be doing after every query; you shouldn't be calling this in your script.
|