Title: $query-&gt;set with array?
Last modified: August 22, 2016

---

# $query->set with array?

 *  [mrspabs](https://wordpress.org/support/users/mrspabs/)
 * (@mrspabs)
 * [11 years, 4 months ago](https://wordpress.org/support/topic/query-set-with-array/)
 * i added this to my fuctions to show only posts of type wines to the homepage.
 *     ```
       function home_posts( $query ) {
           if ( $query->is_home() && $query->is_main_query() ) {
               $query->set( 'post_type', 'wines' );
           }
       }
       add_action( 'pre_get_posts', 'home_posts' );
       ```
   
 * I also want to do 12 posts per page. I wrote it as below but I get error Warning:
   Missing argument 2 for WP_Query::set(),
 *     ```
       function home_posts( $query ) {
           if ( $query->is_home() && $query->is_main_query() ) {
               $query->set(array('post_type' => 'wines', 'posts_per_page' => 12));
           }
       }
       add_action( 'pre_get_posts', 'home_posts' );
       ```
   
 * What is the correct way to write this?

Viewing 1 replies (of 1 total)

 *  Moderator [Marius L. J.](https://wordpress.org/support/users/clorith/)
 * (@clorith)
 * [11 years, 4 months ago](https://wordpress.org/support/topic/query-set-with-array/#post-5654640)
 * Hi,
 * You’ll want to set multiple times (you can use the $query->set() call as many
   times as you need), so in your case you’ll want to do the following
 *     ```
       $query->set( 'post_type' => 'wines' );
       $query->set( 'posts_per_page' => 12 );
       ```
   

Viewing 1 replies (of 1 total)

The topic ‘$query->set with array?’ is closed to new replies.

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 1 reply
 * 2 participants
 * Last reply from: [Marius L. J.](https://wordpress.org/support/users/clorith/)
 * Last activity: [11 years, 4 months ago](https://wordpress.org/support/topic/query-set-with-array/#post-5654640)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
