Custom WordPress Loop
-
I’m looking to modify a custom wordpress loop. Currently, I have it working to pull posts based on meta tag value. But, I want to add in that it has to be in a certain category. I’ve tried dozens of combinations but couldn’t come up with anything. I was hoping someone new the right mix here. Here is what I have so far:
$wp_query->request = " SELECT wposts.* FROM $wpdb->posts wposts, $wpdb->postmeta wpostmeta WHERE wposts.ID = wpostmeta.post_id AND wpostmeta.meta_key = 'meta-value' AND wpostmeta.meta_value = 'yes' AND wposts.post_status = 'publish' AND wposts.post_type = 'post' AND $wpdb->term_taxonomy.term_id = '300' AND $wpdb->term_taxonomy.taxonomy = 'category' ORDER BY wposts.post_date DESC LIMIT $ppp OFFSET $offset ";
So I’m trying to query posts that are published, that have a meta-value = yes and with a category ID of 300. It works without the 2-3 last lines in, but then it pulls posts from all categories. When I try that code, I get the error “Unknown column wp_term_taxonomy.term_id in where clause”. I tried a join statement among other things. However, mysql is not my strong suite.
Thanks for the help1
- The topic ‘Custom WordPress Loop’ is closed to new replies.