Restricting Custom SQL by Category Not Working
-
I’m sure this is a fairly easy question, but I’m pretty new at this.
I’m trying to use SQL to restrict posts by a certain category and sort them by the value of a custom field.
Here’s what I have for the SQL:
$pageposts = $wpdb->get_results(“SELECT wposts.* FROM $wpdb->posts wposts, $wpdb->postmeta wpostmeta
WHERE wposts.ID = wpostmeta.post_id AND wpostmeta.meta_key = ‘productname’ AND wposts.category_id = ‘3’ AND wposts.post_status = ‘publish’ AND wposts.post_date < NOW() ORDER BY wpostmeta.meta_value”, OBJECT);Now here’s the problem. It is sorting correctly, but it is selecting every post, not just the posts in category 3.
Must be something obvious, but…I’m not seeing it.
Thanks.
- The topic ‘Restricting Custom SQL by Category Not Working’ is closed to new replies.