• I’m using this code to pull the most commented posts from the entire database. I was wondering how I can edit it so that it only pulls posts from a select few categories and not the entire database.

    <ul>
    					<?php
    						$sql = "
    							SELECT *
    							FROM $wpdb->posts
    							WHERE 	post_date_gmt > ".(time()-strtotime('-2 weeks'))." AND post_type = 'post'
    							ORDER BY comment_count DESC LIMIT 5
    						";
    
    						$top_posts = $wpdb->get_results($sql);
    
    						foreach ($top_posts as $post)  {
    							?>
    							<li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a><span><a class="comments" href="<?php the_permalink(); ?>#comments"><?php echo $post->comment_count; ?> Comments</a>Posted Under: <?php the_category(', '); ?></span></li>
    							<?
    						}
    					?>
    					</ul>
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Modifying sql to pull posts from select categories’ is closed to new replies.