Title: Unknown table &#8216;wp_posts&#8217; in group statement
Last modified: August 19, 2016

---

# Unknown table ‘wp_posts’ in group statement

 *  Resolved [modifoo](https://wordpress.org/support/users/modifoo/)
 * (@modifoo)
 * [18 years, 6 months ago](https://wordpress.org/support/topic/unknown-table-wp_posts-in-group-statement/)
 * I am getting a new error:
 * >  WordPress database error: [Unknown table ‘wp_posts’ in group statement]
   >  `
   > SELECT ID, post_title FROM wp_posts p LEFT JOIN wp_term_relationships tr ON
   > p.ID = tr.object_id LEFT JOIN wp_term_taxonomy tt ON tr.term_taxonomy_id = 
   > tt.term_taxonomy_id LEFT JOIN wp_ak_popularity pop ON p.ID = pop.post_id WHERE
   > tt.term_id = '467' AND tt.taxonomy = 'category' AND post_status = 'publish'
   > AND post_type = 'post' AND post_date < NOW() GROUP BY wp_posts.ID ORDER BY 
   > pop.total DESC LIMIT 10`
 * This happens only on the categories pages:[Example](http://modifoo.com/category/film/camera-co)
 * Other requests work fine: [Example](http://modifoo.com/1999/04)
 * _wp\_posts does exist…_
 * Here is the php code from the widget:
 *     ```
       <?php /* If this is a 404 page */ if (is_404()) { ?>
       			<?php /* If this is a category archive */ } elseif (is_category()) { ?>
       			<p>You are currently browsing the archives for the <?php single_cat_title(''); ?> category.</p>
   
       			<li><h2>Most Popular in '<?php single_cat_title(''); ?>'</h2>
       				<ul>
       				<?php akpc_most_popular_in_cat(); ?>
       				</ul>
       			</li>
   
       			<?php /* If this is a yearly archive */ } elseif (is_day()) { ?>
       			<p>You are currently browsing the <a href="<?php echo get_settings('siteurl'); ?>"><?php echo bloginfo('name'); ?></a> weblog archives
       			for the day <?php the_time('l, F jS, Y'); ?>.</p>
   
       			<?php /* If this is a monthly archive */ } elseif (is_month()) { ?>
       			<p>You are currently browsing the <a href="<?php echo get_settings('siteurl'); ?>"><?php echo bloginfo('name'); ?></a> weblog archives
       			for <?php the_time('F, Y'); ?>.</p>
   
       			<li><h2>Most Popular in <?php the_time('F, Y'); ?></h2>
       				<ul>
       				<?php akpc_most_popular_in_month(); ?>
       				</ul>
       			</li>
   
             <?php /* If this is a yearly archive */ } elseif (is_year()) { ?>
       			<p>You are currently browsing the <a href="<?php echo get_settings('siteurl'); ?>"><?php echo bloginfo('name'); ?></a> weblog archives
       			for the year <?php the_time('Y'); ?>.</p>
   
       		 <?php /* If this is a monthly archive */ } elseif (is_search()) { ?>
       			<p>You have searched the <a href="<?php echo get_settings('siteurl'); ?>"><?php echo bloginfo('name'); ?></a> weblog archives
       			for <strong>'<?php echo wp_specialchars($s); ?>'</strong>. If you are unable to find anything in these search results, you can try one of these links.</p>
   
       			<?php /* If this is a monthly archive */ } elseif (isset($_GET['paged']) && !empty($_GET['paged'])) { ?>
       			<p>You are currently browsing the <a href="<?php echo get_settings('siteurl'); ?>"><?php echo bloginfo('name'); ?></a> weblog archives.</p>
   
       			<?php } ?>
   
       			<?php if (!is_archive() && !is_category()) { ?>
       			<li><h2>Most Popular Posts</h2>
       				<ul>
       				<?php akpc_most_popular(); ?>
       				</ul>
       			</li>
       			<?php } ?>
       ```
   

Viewing 3 replies - 1 through 3 (of 3 total)

 *  Moderator [Samuel Wood (Otto)](https://wordpress.org/support/users/otto42/)
 * (@otto42)
 * WordPress.org Admin
 * [18 years, 6 months ago](https://wordpress.org/support/topic/unknown-table-wp_posts-in-group-statement/#post-666690)
 * Well, I can tell you what the error is, but I don’t know the widget well enough
   to tell you how to fix it.
 * `GROUP BY wp_posts.ID` is incorrect there because wp_posts has been renamed to“
   p” for the purposes of this select statement. It reads `SELECT ID, post_title
   FROM wp_posts p...` and that “p” makes all the difference.
 * If it was `GROUP BY p.ID` then it would probably work.
 *  Thread Starter [modifoo](https://wordpress.org/support/users/modifoo/)
 * (@modifoo)
 * [18 years, 6 months ago](https://wordpress.org/support/topic/unknown-table-wp_posts-in-group-statement/#post-666696)
 * Thanks Otto.
 * While figuring out how to do this fix, I came across [this comment](http://alexking.org/blog/2007/10/02/popularity-contest-13b2#comment-59344)
   by Dane Morgan. Turns out I am not the only one with this problem and Alex’ plug-
   in:
 * > For the akpc_most_popular_in_cat() problem I have found a solution. I’m guessing
   > it’s a MySQL version issue.
   > Throughout the plugin code there are queries similar to:
   > $posts = mysql_query(”
   >  SELECT p.ID FROM $wpdb->posts p LEFT JOIN $wpdb->ak_popularity
   > pop ON p.ID = pop.post_id
   > By deleting the ‘p’ from each occurance of ‘$wpdb->posts p’
   > and changing each occurance of ‘p.COLUMN_ID’ to ‘$wpdb->posts.COLUMN_ID’
   > I was able to get the most popular by category function to work. Everything
   > else seems to continue working as well.
 * Does that look like a safe fix, or should one not do it. (As in: _I do not know
   anything about SQL and do not want to mess with my database_)
 *  Thread Starter [modifoo](https://wordpress.org/support/users/modifoo/)
 * (@modifoo)
 * [18 years, 5 months ago](https://wordpress.org/support/topic/unknown-table-wp_posts-in-group-statement/#post-666726)
 * SOLVED:
 * Dane Morgan offers a temporary fix on his website:
 * [http://danemorgan.com/popularity-contest-temp-fix-download-for-popular-in-category-feature/24/](http://danemorgan.com/popularity-contest-temp-fix-download-for-popular-in-category-feature/24/)

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Unknown table ‘wp_posts’ in group statement’ is closed to new replies.

## Tags

 * [table](https://wordpress.org/support/topic-tag/table/)
 * [unknown](https://wordpress.org/support/topic-tag/unknown/)
 * [wp_posts](https://wordpress.org/support/topic-tag/wp_posts/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 3 replies
 * 2 participants
 * Last reply from: [modifoo](https://wordpress.org/support/users/modifoo/)
 * Last activity: [18 years, 5 months ago](https://wordpress.org/support/topic/unknown-table-wp_posts-in-group-statement/#post-666726)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
