• Resolved delgado2009

    (@delgado2009)


    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.

Viewing 6 replies - 1 through 6 (of 6 total)
  • Thread Starter delgado2009

    (@delgado2009)

    Any idea?

    Use a query before your code?

    Thread Starter delgado2009

    (@delgado2009)

    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) : ?>
    Thread Starter delgado2009

    (@delgado2009)

    Thank you very much ?? it works great.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Display posts from specific category using a custom select query’ is closed to new replies.