Title: Problem with template
Last modified: August 20, 2016

---

# Problem with template

 *  [karsteng](https://wordpress.org/support/users/karsteng/)
 * (@karsteng)
 * [13 years, 6 months ago](https://wordpress.org/support/topic/problem-with-template-7/)
 * Hi guys. I have a 3.5 problem with a custom made theme. It’s this line:
 * Can any of you help me with what can cause my problem:
    Warning: Missing argument
   2 for wpdb::prepare(), called in….
 * this line:
 * `$request = $wpdb->prepare("SELECT ID, post_title, post_date, post_excerpt,LEFT(
   post_content,$sqllimit) AS short_post_content FROM $wpdb->posts WHERE post_status
   = 'publish' ");`

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

 *  [Damian Gostomski](https://wordpress.org/support/users/damiangostomski/)
 * (@damiangostomski)
 * [13 years, 6 months ago](https://wordpress.org/support/topic/problem-with-template-7/#post-3279339)
 * The prepare function is used to securely substitute placeholders in a SQL query
   with the corresponding values.
 * You can read on how to use it properly and why this error started occurring in
   WordPress 3.5 here: [http://make.wordpress.org/core/2012/12/12/php-warning-missing-argument-2-for-wpdb-prepare/](http://make.wordpress.org/core/2012/12/12/php-warning-missing-argument-2-for-wpdb-prepare/)
 * Assuming $sqllimit is an integer, you should replace it with %d and pass the 
   variable in as the second parameter to the prepare function.
 *  Thread Starter [karsteng](https://wordpress.org/support/users/karsteng/)
 * (@karsteng)
 * [13 years, 6 months ago](https://wordpress.org/support/topic/problem-with-template-7/#post-3279364)
 * Oh I guess I am not that clever when it comes to code ;-). I tried changing it
   to %d but then my site was really weird. Can anyone guide me?
 *  [Andrew Nevins](https://wordpress.org/support/users/anevins/)
 * (@anevins)
 * WCLDN 2018 Contributor | Volunteer support
 * [13 years, 6 months ago](https://wordpress.org/support/topic/problem-with-template-7/#post-3279365)
 * Try this
 *     ```
       $post_status = 'publish';
       $request = $wpdb->prepare("SELECT ID, post_title, post_date, post_excerpt,LEFT(post_content,$sqllimit) AS short_post_content FROM $wpdb->posts WHERE post_status = %d ", $post_status);
       ```
   
 *  [Damian Gostomski](https://wordpress.org/support/users/damiangostomski/)
 * (@damiangostomski)
 * [13 years, 6 months ago](https://wordpress.org/support/topic/problem-with-template-7/#post-3279366)
 * Andrew – If you use %d as a placeholder, then it will expect an integer, not 
   a string.
 * Something like this should work (not tested):
    `$request = $wpdb->prepare("SELECT
   ID, post_title, post_date, post_excerpt,LEFT(post_content, %d) AS short_post_content
   FROM $wpdb->posts WHERE post_status = 'publish' ", $sqllimit);`
 * Let me know if that resolves the issue. It’s also worth reading the Codex on 
   the WPDB class to get a better understanding of it: [http://codex.wordpress.org/Class_Reference/wpdb](http://codex.wordpress.org/Class_Reference/wpdb)
 *  Thread Starter [karsteng](https://wordpress.org/support/users/karsteng/)
 * (@karsteng)
 * [13 years, 6 months ago](https://wordpress.org/support/topic/problem-with-template-7/#post-3279372)
 * Damian… You are a hero 🙂 It worked perfect!! Thanks a lot!

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

The topic ‘Problem with template’ is closed to new replies.

 * 5 replies
 * 3 participants
 * Last reply from: [karsteng](https://wordpress.org/support/users/karsteng/)
 * Last activity: [13 years, 6 months ago](https://wordpress.org/support/topic/problem-with-template-7/#post-3279372)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
