Title: PHP code change help needed!
Last modified: August 19, 2016

---

# PHP code change help needed!

 *  [crisp82](https://wordpress.org/support/users/crisp82/)
 * (@crisp82)
 * [15 years, 10 months ago](https://wordpress.org/support/topic/php-code-change-help-needed/)
 * Hi,
 * I am trying to change the following code to list 10 posts:
 *     ```
       $the_query = new WP_Query('showposts='. $posts .'&orderby=post_date&order=desc');
       	while ($the_query->have_posts()) : $the_query->the_post();
       ```
   
 * I have tried the following without success:
 *     ```
       $the_query = new WP_Query('showposts='. $posts .'&orderby=post_date&order=desc', 'posts_per_page = 10');
       	while ($the_query->have_posts()) : $the_query->the_post();
       ```
   
 *     ```
       $the_query = new WP_Query('showposts='. $posts .'&orderby=post_date&order=desc', 'posts_per_page' => 10);
       	while ($the_query->have_posts()) : $the_query->the_post();
       ```
   
 *     ```
       $the_query = new WP_Query('showposts='. $posts .'&orderby=post_date&order=desc', 'posts_per_page=10');
       	while ($the_query->have_posts()) : $the_query->the_post();
       ```
   
 * The first one does nothing, the second and third list PHP errors on loading the
   site.
 * This code does list 10, but not in the way that I need:
 *     ```
       $loop = new WP_Query( array( 'post_type' => 'post', 'posts_per_page' => 10 ) );
       while ( $loop->have_posts() ) : $loop->the_post();
       ```
   

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

 *  [Michael](https://wordpress.org/support/users/alchymyth/)
 * (@alchymyth)
 * [15 years, 10 months ago](https://wordpress.org/support/topic/php-code-change-help-needed/#post-1581060)
 * this is the setting of the number of posts in your original code:
 * `'showposts='. $posts .'`
 * ‘showposts’ is deprecated for ‘posts_per_page; and `$posts` is a variable holding
   the number of posts to show.
 * changing your code to the following should work:
 *     ```
       $the_query = new WP_Query('posts_per_page=10&orderby=post_date&order=desc');
       	while ($the_query->have_posts()) : $the_query->the_post();
       ```
   
 *  Thread Starter [crisp82](https://wordpress.org/support/users/crisp82/)
 * (@crisp82)
 * [15 years, 10 months ago](https://wordpress.org/support/topic/php-code-change-help-needed/#post-1581084)
 * This has not worked. The code is in the ‘theme-functions.php’ of the theme I 
   am using (The morning after).
 * Putting
 *     ```
       $the_query = new WP_Query('posts_per_page=10&orderby=post_date&order=desc');
       	while ($the_query->have_posts()) : $the_query->the_post();
       ```
   
 * into the home.php will display 10 results, but it does not organise itself based
   on the CSS as the ‘Latest Post’ section does. Very frustrating!

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

The topic ‘PHP code change help needed!’ is closed to new replies.

 * 2 replies
 * 2 participants
 * Last reply from: [crisp82](https://wordpress.org/support/users/crisp82/)
 * Last activity: [15 years, 10 months ago](https://wordpress.org/support/topic/php-code-change-help-needed/#post-1581084)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
