Title: query posts problem
Last modified: August 19, 2016

---

# query posts problem

 *  [emotionaljoystick](https://wordpress.org/support/users/emotionaljoystick/)
 * (@emotionaljoystick)
 * [18 years, 4 months ago](https://wordpress.org/support/topic/query-posts-problem/)
 * Hi there. I have a wordpress site, and I need the main page to only display posts
   from one category. I’ve used “query posts” before with success, so I tried putting
   this right after the head, on the index.php page (as I did before):
 *     ```
       <?php
          if (is_home()) {
             query_posts("cat=2");
          }
       ?>
       ```
   
 * And it does indeed display posts from Category 2 first, but then I get two instances
   of an error (I happen to have 2 other posts, in a different category), you can
   view the results here:
 * [http://www.slowpitchpr.com/wp/](http://www.slowpitchpr.com/wp/)
 * Very strange, and everything works without that query posts bit (it just displays
   all posts)… Here is the code for the index.php file, I’m thinking something is
   not structured correctly here:
 *     ```
       <?php get_header(); ?>
       			<div id="main">
       				<div id="content">
       <?php
          if (is_home()) {
             query_posts("cat=2");
          }
       ?>
       					<?php if ($posts) : foreach ($posts as $post) : start_wp(); ?>
       			    <div class="post">
                   <p class="cat"><?php the_category(', ') ?></p>
                   <h2 class="post-title">
                     <a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link: <?php the_title(); ?>"><?php the_title(); ?></a>
                   </h2>
       				    <div class="post-content">
                       <?php the_content('Continue Reading »'); ?>
                       <?php wp_link_pages(); ?>
       				        <!--
       				          <?php trackback_rdf(); ?>
       				        -->
       			      </div>
                   <p class="post-info">
                       <em class="date"><?php the_time('d M Y'); ?></em>
                       <em class="user"><?php the_author_posts_link() ?></em>
                       <span><?php edit_post_link(); ?></span>
                       <span class="post-comments"><?php comments_popup_link('0 comments', '1 comment', '% comments','','comments off'); ?></span>
                   </p>
       			      <?php comments_template(); ?>
       		      </div>
       			<?php endforeach; else: ?>
       			  <p><?php _e('Sorry, no posts matched your criteria.'); ?></p>
       			<?php endif; ?>
       		  <p align="center"><?php posts_nav_link(' - ','« Prev','Next »') ?></p>
       	</div>
        <?php get_sidebar();?>
       <?php get_footer();?>
       ```
   

The topic ‘query posts problem’ is closed to new replies.

## Tags

 * [query_posts](https://wordpress.org/support/topic-tag/query_posts/)
 * [sql-error](https://wordpress.org/support/topic-tag/sql-error/)

 * 0 replies
 * 1 participant
 * Last reply from: [emotionaljoystick](https://wordpress.org/support/users/emotionaljoystick/)
 * Last activity: [18 years, 4 months ago](https://wordpress.org/support/topic/query-posts-problem/)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
