You need to make sure that the $currentcat variable is set before this query runs. This should be the id of the category you want to pull top posts from.
$sql = "SELECT count(mr.post_ID) AS totHits, p.ID, p.post_title FROM $wpdb->posts p
JOIN {$wpdb->prefix}kf_most_read mr ON mr.post_ID = p.ID
JOIN {$wpdb->prefix}term_taxonomy ON ($wpdb->term_relationships.term_taxonomy_id = $wpdb->term_taxonomy.term_taxonomy_id)
WHERE mr.hit_ts >= '".(time() - ( 86400 * $period))."'
AND $wpdb->term_taxonomy.taxonomy = 'category'
AND $wpdb->term_taxonomy.term_id IN ($currentcat)
GROUP BY mr.post_ID ORDER BY totHits DESC, ID ASC LIMIT $limit";
Related Posts:
- Get posts from sites in Multisite?
- How To Modify The Loop in archives.php To Have 11 Posts Per Page and CSS Styling
- Using categories & “stickyness” together
- Does the ‘cat’ argument in query_posts fetch posts from subcategories as well as the given ID?
- List posts by category exclude current post
- Display only the latest post from multiple categories
- Select category in custom query
- Display one latest post from multiple categories
- Deleting All tags except categories Wp database
- Return category slug / title from category ID
- Exclude category from loop not working
- “NOT ONLY IN” taxonomy query operator?
- Post count for category and tag
- Checking for two categories in query_posts
- How to query post like normal search would do. within search.php page
- Query Posts Exclude Entire Category
- how to query posts and auto assign category if post title has keyword
- How do I call posts with a certain tag?
- query order by category
- Get link which associated with a specific category and tag
- batch adding posts to a category based on matching regex for title with SQL
- SQL to migrate post types to taxonomy
- Order by category titles
- Have parent category contain only one post?
- Custom SQL Query: Get all posts with category id and a concated list of tags on each post
- List posts in alphabetical order
- Get posts under a category with SQL
- Randomly load categories with latest post
- Set colors depending on category
- How do I query_posts in cat=1 AND not in cat=2
- List all posts in a category with query_post() function
- query_post order desc
- Exclude a category from a query that includes its parent category
- Get a count of how many times a term or a category is used in posts
- Show the latest post from child category?
- Pagination on category.php and tag.php not working
- Problem with different query loops (and “main loop”) on category template page!
- query_posts not reading correct categories
- SQL query to return categories and category parents
- Pagination for query_posts();
- Overriding default calendar to show posts from a category
- Posts from a category on homepage with category archieves page default css
- function query_posts disabling current_page_menu class
- query_posts by category_name and custom taxonomy
- wordpress taxonomy query posts
- PHP dynamical conditional post display
- Posts of specific category on page and excluded from index.htm
- new WP_Query issues
- SQL query to get posts from multiple categories but not in a category
- how can i hide category?
- Displaying links to all posts of the same category on the post page
- Post not found when filtered by category ID
- Assign a list of categories with a parent category
- Exclude categories from postquery
- Sort posts alphabetically by category/custom taxonomy, insert divider between different types
- Show posts from category specified using a custom field
- query_post problem
- Add class to current post in query_post
- Different post slug based on archive
- Get category from slug list
- Pagination does not work with query_posts()
- Bulk Change WordPress category Slug
- Assign a class to first element in category in loop
- How to display products with multiple conditions, product_id and category_id
- Query post only from categories that have subcategories
- Help with SQL query, how to add taxonomie terms with value stored in options?
- Displaying posts by year
- Paginate WordPress Category Pages
- finding out the top 5 source ( source is a custom taxonomy ), in a given category
- How to have a category not show up in query post with page panigation?
- Query pages by category
- Showing one post from each category, paged?
- How to add featured image for category (without a plugin)?
- Query only Posts from Both of Two Category?
- Action hooks returning old category instead of new category
- Category checkboxes in upload modal
- Custom WP_Query for current category (in category.php)?
- Why is get_the_category() saying that I have two categories?
- Custom sidebar on category pages
- How do I get the category slug from wp_dropdown_categories
- exclude categories from search results
- List categories with posts
- wp_list_categories set order manually?
- Putting a Category of posts under a Page
- change recent posts based on category
- Getting category URL with hyphens, not spaces
- How can I change the tooltip in the_category?
- Category.php loads first before page.php?
- how to get correct category of a post in case of multiple categories?
- Show button only for certain Woocommerce Product Categories
- Length of Category Names
- Is it possible to create an alias/custom taxonomy for a category name?
- Multiple category columns and post counting list in wordpress Homepage
- Product category display in tabs
- Sending all categories associated with a post to Google Ad Manager for use with .setTargeting
- Pull in an “Include” file based on a WordPress Category ID
- Why is URL Slug Saving Differently From How It’s Been Defined?
- How to noindex, follow a specific category wordpress?
- Listing category
- Weird html output of single_cat_title – is not inside of the html element?