Title: query_posts in theme file
Last modified: August 30, 2016

---

# query_posts in theme file

 *  Resolved [zacorehawa](https://wordpress.org/support/users/zacorehawa/)
 * (@zacorehawa)
 * [10 years, 7 months ago](https://wordpress.org/support/topic/query_posts-in-theme-file/)
 * Hello,
 * Im trying to show all my blog posts except ones in “for-sale” category (number
   7.
 * This will work to have everything as I want it expect it shows all blog posts.
 * Any ideas? Thanks
 *     ```
       <?php
       /*
       Template Name: Blog
       */
       get_header(); 
   
       		$args = array(
       		'post_type' => 'post',
       		'posts_per_page' => 2,
       		'cat' => '-7',
       		'paged' => ( get_query_var('paged') ? get_query_var('paged') : 1 )
       	);
       	query_posts($args);
       	include( get_home_template() );
       	wp_reset_query();
       get_footer();
       ?>
       ```
   

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

 *  [Mark Wilkinson](https://wordpress.org/support/users/wpmarkuk/)
 * (@wpmarkuk)
 * [10 years, 7 months ago](https://wordpress.org/support/topic/query_posts-in-theme-file/#post-6636531)
 * I would look at the `pre_get_posts` action hook for doing something like this:
 * [https://codex.wordpress.org/Plugin_API/Action_Reference/pre_get_posts](https://codex.wordpress.org/Plugin_API/Action_Reference/pre_get_posts)
 *  Thread Starter [zacorehawa](https://wordpress.org/support/users/zacorehawa/)
 * (@zacorehawa)
 * [10 years, 7 months ago](https://wordpress.org/support/topic/query_posts-in-theme-file/#post-6636558)
 * Hello thanks for getting back to me.
 * I was really silly and was caching the page! It’s all working with the code above
   now!
 * Thanks

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

The topic ‘query_posts in theme file’ is closed to new replies.

## Tags

 * [custom](https://wordpress.org/support/topic-tag/custom/)
 * [page](https://wordpress.org/support/topic-tag/page/)
 * [posts](https://wordpress.org/support/topic-tag/posts/)
 * [query_posts](https://wordpress.org/support/topic-tag/query_posts/)
 * [template](https://wordpress.org/support/topic-tag/template/)

 * 2 replies
 * 2 participants
 * Last reply from: [zacorehawa](https://wordpress.org/support/users/zacorehawa/)
 * Last activity: [10 years, 7 months ago](https://wordpress.org/support/topic/query_posts-in-theme-file/#post-6636558)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
