Title: Need Help With WP_Query (sort order)
Last modified: August 21, 2016

---

# Need Help With WP_Query (sort order)

 *  Resolved [Justin Case](https://wordpress.org/support/users/the-buddha-garden/)
 * (@the-buddha-garden)
 * [12 years, 11 months ago](https://wordpress.org/support/topic/need-help-with-wp_query-sort-order/)
 * I keep killing my site when trying to modify the arguments in a WP_Query
 * If I try to add a sort order such as:
 * `'orderby' => 'title'`
 * To the arguments, then the site crashes.
 * Here is how I am passing the arguments:
 *     ```
       $args = array(
               'post_parent' => $post->ID,
               'post_type' => 'page'
               'orderby' => 'title'
           );
           $subpages = new WP_query($args);
       ```
   
 * But if I leave it OUT of the arguments, then It won’t crash. For example, it 
   works fine if I just do this:
 *     ```
       $args = array(
               'post_parent' => $post->ID,
               'post_type' => 'page'
           );
           $subpages = new WP_query($args);
       ```
   
 * But once I add ‘orderby’ => ‘title’, the site and the admin crash (just a white
   screen, no source is output to the screen at all).
 * And yes, I am trying to return pages, not posts.
 * I really am not sure what is going wrong.
 * If it helps, I am trying to use this whole bit of code for displaying child pages
   and their descriptions. The entire bit of code is:
 *     ```
       function subpage_peek() {
           global $post;  
   
           //query subpages
           $args = array(
               'post_parent' => $post->ID,
               'post_type' => 'page'
           );
           $subpages = new WP_query($args);  
   
           // create output
           if ($subpages->have_posts()) :
               $output = '<ul>';
               while ($subpages->have_posts()) : $subpages->the_post();
                   $output .= '<li><strong><a href="'.get_permalink().'">'.get_the_title().'</a></strong>
                               <p>'.get_the_excerpt().'<br />
                               <a href="'.get_permalink().'">Continue Reading ?</a></p></li>';
               endwhile;
               $output .= '</ul>';
           else :
               $output = '<p>No subpages found.</p>';
           endif;  
   
           // reset the query
           wp_reset_postdata();  
   
           // return something
           return $output;
       }
   
       add_shortcode('subpage_peek', 'subpage_peek');
   
       // displays category descriptions as well as names - call with desc_cats()
   
       function desc_cats(){
       foreach (get_categories(array('hide_empty'=>true)) as $category)
       {
       $catid = $category->cat_ID;
       echo '<li><a href="' . get_bloginfo('wpurl') . '/' .  $category->category_nicename . '/">' .
       	$category->cat_name . ' (' . $category->count.$numposts.')</a>' . category_description($catid) . '</li>';
       }
       echo'<p>'; // puts a paragraph tag after last category description listed
       };
       ```
   

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

 *  [Josh](https://wordpress.org/support/users/josh401/)
 * (@josh401)
 * [12 years, 11 months ago](https://wordpress.org/support/topic/need-help-with-wp_query-sort-order/#post-4128923)
 * Your syntax is incorrect in the first block of code you posted:
 *     ```
       $args = array(
               'post_parent' => $post->ID,
               'post_type' => 'page'
               'orderby' => 'title'
           );
           $subpages = new WP_query($args);
       ```
   
 * Whenever you are passing arguments, they MUST be comma-separated EXCEPT for the
   last argument.
 * Here is the correct syntax:
 *     ```
       $args = array(
           'post_parent' => $post->ID,
           'post_type' => 'page', // <- Note the comma
           'orderby' => 'title'
       );
       $subpages = new WP_query($args);
       ```
   
 *  Thread Starter [Justin Case](https://wordpress.org/support/users/the-buddha-garden/)
 * (@the-buddha-garden)
 * [12 years, 11 months ago](https://wordpress.org/support/topic/need-help-with-wp_query-sort-order/#post-4128927)
 * Thanks so much, Josh!!!
 * Really appreciate the assist. Don’t know how I overlooked the missing comma.
 * ~~~
 * By the way: Is there a way for a moderator to mark this thread as resolved? I
   don’t seem to be able to do that here.
 *  [Josh](https://wordpress.org/support/users/josh401/)
 * (@josh401)
 * [12 years, 11 months ago](https://wordpress.org/support/topic/need-help-with-wp_query-sort-order/#post-4128941)
 * My pleasure.
 * Yeah, mods can mark as resolved.
 * But so can the original poster (OP in WordPress jargon).
 * Look over at the right of the screen where it says “About this topic”. Under 
   there should be a dropdown where you can select the status of the topic.
 * Choose “resolved” and click update.
 *  Thread Starter [Justin Case](https://wordpress.org/support/users/the-buddha-garden/)
 * (@the-buddha-garden)
 * [12 years, 11 months ago](https://wordpress.org/support/topic/need-help-with-wp_query-sort-order/#post-4129041)
 * Thanks again.
 * Don’t know how I missed it. Been working too long on this project that I am overlooking
   some of the obvious things.

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

The topic ‘Need Help With WP_Query (sort order)’ is closed to new replies.

## Tags

 * [subpage](https://wordpress.org/support/topic-tag/subpage/)
 * [wp_query](https://wordpress.org/support/topic-tag/wp_query/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 4 replies
 * 2 participants
 * Last reply from: [Justin Case](https://wordpress.org/support/users/the-buddha-garden/)
 * Last activity: [12 years, 11 months ago](https://wordpress.org/support/topic/need-help-with-wp_query-sort-order/#post-4129041)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
