$wpdb get_results – loop from specific category
-
I have this code, its working good, but its gets posts from all categories. I need to get posts only from category ID 2. I tried to add “AND term_taxonomy_id = 2” to my code, but this didint work. Can somebody help me with this, my code:
<?php //loops all posts $my_query = $wpdb->get_results ("SELECT * FROM <code>{$table_prefix}posts</code>, {$table_prefix}postmeta WHERE {$table_prefix}posts.post_status = 'publish' AND {$table_prefix}posts.id = {$table_prefix}postmeta.post_id AND {$table_prefix}postmeta.<code>meta_key</code> = 'wpcf-data-nuo' ORDER BY if({$table_prefix}postmeta.<code>meta_value</code> = '' or {$table_prefix}postmeta.<code>meta_value</code> is null,1,0), {$table_prefix}postmeta.<code>meta_value</code> ASC LIMIT 12"); foreach($my_query as $post) { setup_postdata($post); ?>
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘$wpdb get_results – loop from specific category’ is closed to new replies.