Title: &#8216;error in your SQL syntax&#8217; when using get_posts
Last modified: August 18, 2016

---

# ‘error in your SQL syntax’ when using get_posts

 *  [aylia](https://wordpress.org/support/users/aylia/)
 * (@aylia)
 * [20 years, 3 months ago](https://wordpress.org/support/topic/error-in-your-sql-syntax-when-using-get_posts/)
 * I’ve just upgraded to the new wordpress, and am having trouble restoring my front
   page to its former glory. With the settings left alone all posts appear fine,
   with no error message. If I try this, however:
 *  <?php
    $posts = get_posts(‘numberposts=5&offset=1&category=2’); foreach($posts
   as $post) : ?> “><?php the_title(); ?> — <?php the_excerpt(); ?> <?php endforeach;?
   >
 * This error message appears:
 * WordPress database error: [You have an ; check the manual that corresponds to
   your MySQL server version for the right syntax to use near ‘AND comment_approved
   = ‘1” at line 1]
    SELECT COUNT(comment_ID) FROM wp_comments WHERE comment_post_ID
   = AND comment_approved = ‘1’;
 * can anyone tell me why? My aim is to have 1 posts from each of 5 categories on
   the front page, with links to 3-5 articles underneath.
 * Thanks for your help.

The topic ‘‘error in your SQL syntax’ when using get_posts’ is closed to new replies.

## Tags

 * [get_posts](https://wordpress.org/support/topic-tag/get_posts/)
 * [message](https://wordpress.org/support/topic-tag/message/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 0 replies
 * 1 participant
 * Last reply from: [aylia](https://wordpress.org/support/users/aylia/)
 * Last activity: [20 years, 3 months ago](https://wordpress.org/support/topic/error-in-your-sql-syntax-when-using-get_posts/)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
