Title: Query Posts syntax
Last modified: August 21, 2016

---

# Query Posts syntax

 *  [paramasivanpn](https://wordpress.org/support/users/paramasivanpn/)
 * (@paramasivanpn)
 * [12 years, 7 months ago](https://wordpress.org/support/topic/query-posts-syntax/)
 * Hi,
 * In the bought out theme it is like
 *     ```
       if ( is_page() ) {
           $paged = get_query_var('paged') ? get_query_var('paged') : 1;
           query_posts( 'post_type=post&paged=' . $paged );
       }
       ```
   
 * I want to modify the above code to include only category “Collaborations” and
   not all posts to be displayed.
 * How to modify the code?
 * Thank you,

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

 *  [Scriptrunner (Doug Sparling)](https://wordpress.org/support/users/scriptrunner/)
 * (@scriptrunner)
 * [12 years, 7 months ago](https://wordpress.org/support/topic/query-posts-syntax/#post-4163083)
 * The code in the bought out theme isn’t using parameterized queries, and could
   be susceptible to SQL injection:
 * So to address that and answer your question, change:
 *     ```
       if ( is_page() ) {
           $paged = get_query_var('paged') ? get_query_var('paged') : 1;
           query_posts( 'post_type=post&paged=' . $paged );
       }
       ```
   
 * to
 *     ```
       if ( is_page() ) {
           $paged = get_query_var('paged') ? get_query_var('paged') : 1;
           query_posts( array ( 'post_type' => 'post', 'category_name' => 'Collaborations', 'posts_per_page' => 5, 'paged' => $paged ) );
       }
       ```
   
 * Big caveat, I wrote this in the forum text area (I haven’t tried running it),
   so I’ll make sure it’s valid when I get back in front of my work computer.
 *  Thread Starter [paramasivanpn](https://wordpress.org/support/users/paramasivanpn/)
 * (@paramasivanpn)
 * [12 years, 7 months ago](https://wordpress.org/support/topic/query-posts-syntax/#post-4163088)
 * Sorry ; It displays other post categories also (including uncategorized).
 *  [Scriptrunner (Doug Sparling)](https://wordpress.org/support/users/scriptrunner/)
 * (@scriptrunner)
 * [12 years, 7 months ago](https://wordpress.org/support/topic/query-posts-syntax/#post-4163119)
 * OK, looks like you need to use the category slug:
 * `'category_name' => 'my-category-slug'`
 * or category id:
 * `'cat' => 22`
 * Sorry about that…
 *  Thread Starter [paramasivanpn](https://wordpress.org/support/users/paramasivanpn/)
 * (@paramasivanpn)
 * [12 years, 7 months ago](https://wordpress.org/support/topic/query-posts-syntax/#post-4163297)
 * Sorry, nothing works in this bought out theme.
 * The theme author suggested to make the menu (appearance -> menus) to choose the
   category “Collaboration” as the menu item and it worked.
 * [http://test.skinnycreative.com/projects/aob/category/collaborations-cat/](http://test.skinnycreative.com/projects/aob/category/collaborations-cat/)

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

The topic ‘Query Posts syntax’ is closed to new replies.

## Tags

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

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 4 replies
 * 2 participants
 * Last reply from: [paramasivanpn](https://wordpress.org/support/users/paramasivanpn/)
 * Last activity: [12 years, 7 months ago](https://wordpress.org/support/topic/query-posts-syntax/#post-4163297)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
