Forums

Modifying sql to pull posts from select categories (3 posts)

  1. JGrizzLee
    Member
    Posted 9 months ago #

    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>
  2. JGrizzLee
    Member
    Posted 9 months ago #

    anybody? =/

  3. JGrizzLee
    Member
    Posted 9 months ago #

    can a mod please move this to the advanced forum so it has a higher chance of being found by somebody who could help?

Reply

You must log in to post.

About this Topic