Title: query_posts returns pages
Last modified: August 21, 2016

---

# query_posts returns pages

 *  [Bram](https://wordpress.org/support/users/bramos_ditaljanos/)
 * (@bramos_ditaljanos)
 * [12 years, 11 months ago](https://wordpress.org/support/topic/query_posts-returns-pages/)
 * Hi there,
 * In my website, I have an activities-page. On this page, the content of the ‘activities’-
   page is displayed first, followed by all posts (which contain the actual events)
   below. To make users select which categories of posts they’d like to show, I’d
   like to add categories to the ‘activities’-page (using this plugin) which works
   great.
 * Displaying these posts/events, however, gives some difficulties. Below is the
   code I’m using. $categories is an array with the categories that need to be displayed,
   $main_id is the ID of the activities-page.
 *     ```
       <?php for($i = 0; $i < count($categories); $i++){ ?>
               <div class="activiteiten">
                   <?php
                       $post_array = query_posts(array('post_per_page' => '-1', 'post_type' => 'post', 'category_name' => $categories[$i], 'exclude' => $main_id, 'post_status' => 'publish'));
                       echo "<h1>". $categories[$i] ."</h1>";       
   
                           if (have_posts()) :
                           	while (have_posts()) : the_post(); ?>
                           	<div class="activiteit">
                           		<h2><a href="<?php the_permalink() ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></h2>
                           		<div class="activiteitinfo">
                                       <a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>">
                           				<?php if ( has_post_thumbnail()) : the_post_thumbnail(); else : ?>
                           					<img src="<?php bloginfo('template_directory'); ?>/img/no-thumbnail.png" width="110px" class="" />
                           				<?php endif; ?>
                           		    </a>
                           			<?php the_excerpt(); ?>
                           			<p class="meer"><a href="<?php the_permalink(); ?>">Lees verder &raquo;</a></p>
                           		</div><!-- /.activiteitinfo -->
                               </div><!-- /.activiteit -->
                           	<?php endwhile;
                       ?>
                       <?php else : ?>
                           <p>Op dit moment zijn er geen activiteiten in deze categorie gepland.</p>
                       <?php endif; ?>
               </div>
               <?php }
           ?>
       ```
   
 * The problem is in the query_posts-function. If I add the ‘category_name’-parameter,
   the ‘post-type’- and ‘exclude’-parameters are neglected.
 * Thanks a lot for any help and tips,
    Bram
 * [http://wordpress.org/extend/plugins/post-tags-and-categories-for-pages/](http://wordpress.org/extend/plugins/post-tags-and-categories-for-pages/)

Viewing 1 replies (of 1 total)

 *  Plugin Author [curtismchale](https://wordpress.org/support/users/curtismchale/)
 * (@curtismchale)
 * [12 years, 11 months ago](https://wordpress.org/support/topic/query_posts-returns-pages/#post-3909101)
 * You should never use query_posts if you think you should use it, think again.
 * Below are 2 great resources to learn more about why you really shouldn’t be using
   query_posts ever.
 * [http://developer.wordpress.com/2012/05/14/querying-posts-without-query_posts/](http://developer.wordpress.com/2012/05/14/querying-posts-without-query_posts/)
   
   [http://wordpress.tv/2013/03/15/andrew-nacin-wp_query-wordpress-in-depth/](http://wordpress.tv/2013/03/15/andrew-nacin-wp_query-wordpress-in-depth/)
 * This really isn’t a ‘support’ question for my plugin either and will get more
   attention on wordpress.stackexchange.com or on the main forums here.

Viewing 1 replies (of 1 total)

The topic ‘query_posts returns pages’ is closed to new replies.

 * ![](https://s.w.org/plugins/geopattern-icon/post-tags-and-categories-for-pages.
   svg)
 * [Post Tags and Categories for Pages](https://wordpress.org/plugins/post-tags-and-categories-for-pages/)
 * [Support Threads](https://wordpress.org/support/plugin/post-tags-and-categories-for-pages/)
 * [Active Topics](https://wordpress.org/support/plugin/post-tags-and-categories-for-pages/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/post-tags-and-categories-for-pages/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/post-tags-and-categories-for-pages/reviews/)

## Tags

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

 * 1 reply
 * 2 participants
 * Last reply from: [curtismchale](https://wordpress.org/support/users/curtismchale/)
 * Last activity: [12 years, 11 months ago](https://wordpress.org/support/topic/query_posts-returns-pages/#post-3909101)
 * Status: not a support question