Excluding categories from popular posts (1 post)

  1. beautifulamazingworld
    Posted 3 years ago #

    I have a function that displays the top 5 popular posts, but I need to remove categories from it so they don't appear in the popular posts section. The code is...

    function wp_popular_posts($pop_posts = 5 , $thumb = true){
    	global $wpdb , $post;
    	$orig_post = $post;
    	$popularposts = "SELECT ID,post_title,post_date,post_author,post_content,post_type FROM $wpdb->posts WHERE post_status = 'publish' AND post_type = 'post' ORDER BY comment_count DESC LIMIT 0,".$pop_posts;
    	$posts = $wpdb->get_results($popularposts);
    		global $post;
    		foreach($posts as $post){

    Then it goes on to print out the post. I wanted to know if there's an easy way to exclude certain categories within this??

    I know about query_posts(cat=-4) but not sure if I could use that method here? if so where should I put it?

    Any help is appreciated, thanks in advance!

Topic Closed

This topic has been closed to new replies.

About this Topic

  • RSS feed for this topic
  • Started 3 years ago by beautifulamazingworld
  • This topic is not resolved
  • WordPress version: 3.4.2