Title: Ordering by Specific Category PHP
Last modified: August 19, 2016

---

# Ordering by Specific Category PHP

 *  Resolved [artslob](https://wordpress.org/support/users/artslob/)
 * (@artslob)
 * [15 years, 3 months ago](https://wordpress.org/support/topic/ordering-by-specific-category-php/)
 * Hello. I’m trying to make a category display instead of random posts in slide.
   php of Zinmag Tribune theme.
 * I’m editing slide.php which rotates thumbnails and descriptions of certain posts.
   originally the code looked like this
 * $my_query = new WP_Query(‘orderby=rand &showpost=2’);
    while ($my_query->have_posts()):
   $my_query->the_post();$do_not_duplicate = $post->ID;
 * I would just like to switch the ‘orderby=rand to display posts from a specific
   category instead of random posts.
 * I did change it to ‘orderby=category and it is now only displaying posts from
   the front page for some reason. Any help greatly appreciated.
 * cheers

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

 *  Moderator [keesiemeijer](https://wordpress.org/support/users/keesiemeijer/)
 * (@keesiemeijer)
 * [15 years, 3 months ago](https://wordpress.org/support/topic/ordering-by-specific-category-php/#post-1943386)
 * try:
 * `my_query = new WP_Query('posts_per_page=2&cat=8');`
 * Change 8 to the category ID you want
 * [http://codex.wordpress.org/Function_Reference/query_posts](http://codex.wordpress.org/Function_Reference/query_posts)
 *  Thread Starter [artslob](https://wordpress.org/support/users/artslob/)
 * (@artslob)
 * [15 years, 3 months ago](https://wordpress.org/support/topic/ordering-by-specific-category-php/#post-1943391)
 * works like a charm! Thank you so much!
 * It should be noted that you also need a $ at the beginning for the call to function
   
   $my_query = new WP_Query(‘posts_per_page=2&cat=8’);
 *  Moderator [keesiemeijer](https://wordpress.org/support/users/keesiemeijer/)
 * (@keesiemeijer)
 * [15 years, 3 months ago](https://wordpress.org/support/topic/ordering-by-specific-category-php/#post-1943393)
 * Oops, didn’t copy paste the whole thing. Glad you got it working.

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

The topic ‘Ordering by Specific Category PHP’ is closed to new replies.

## Tags

 * [category](https://wordpress.org/support/topic-tag/category/)
 * [orderby](https://wordpress.org/support/topic-tag/orderby/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 3 replies
 * 2 participants
 * Last reply from: [keesiemeijer](https://wordpress.org/support/users/keesiemeijer/)
 * Last activity: [15 years, 3 months ago](https://wordpress.org/support/topic/ordering-by-specific-category-php/#post-1943393)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
