WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Unknown table 'wp_posts' in group statement (4 posts)

  1. modifoo
    Member
    Posted 6 years ago #

    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

    Other requests work fine: Example

    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 } ?>
  2. Samuel Wood (Otto)
    Tech Ninja
    Posted 6 years ago #

    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.

  3. modifoo
    Member
    Posted 6 years ago #

    Thanks Otto.

    While figuring out how to do this fix, I came across this comment 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)

  4. modifoo
    Member
    Posted 6 years ago #

Topic Closed

This topic has been closed to new replies.

About this Topic