delgado2009
Member
Posted 1 year ago #
Hi,I have this code and i want to display those posts from specific category...
<?$pop = $wpdb->get_results("SELECT id, post_title, comment_count
FROM {$wpdb->prefix}posts
WHERE post_type='post'
ORDER BY comment_count DESC LIMIT 9");
foreach($pop as $post) : ?>
List posts....
<?php endforeach; ?>`
Thank you in advance.
delgado2009
Member
Posted 1 year ago #
Use a query before your code?
delgado2009
Member
Posted 1 year ago #
Don't work ... I'm thinking of a code would be introduced in my code for the category.
Then I don't know, sorry.
If what you want is to modify the query, try this:
<? $cat_id = 14; // The category id to select
$pop = $wpdb->get_results("SELECT p.id, p.post_title, p.comment_count
FROM $wpdb->posts p
JOIN $wpdb->term_relationships tr ON (p.ID = tr.object_id)
JOIN $wpdb->term_taxonomy tt ON (tr.term_taxonomy_id = tt.term_taxonomy_id)
JOIN $wpdb->terms t ON (tt.term_id = t.term_id)
WHERE p.post_type='post'
AND p.post_status = 'publish'
AND tt.taxonomy = 'category'
AND t.term_id = $cat_id
ORDER BY comment_count DESC LIMIT 9");
foreach($pop as $post) : ?>
delgado2009
Member
Posted 1 year ago #
Thank you very much :) it works great.