WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm facing a strange issue displaying all posts of a certain type of custom post sorted by their category. The code below to display them works fine locally but when I view the page on the server it returns an archive page with three posts instead. How is that possible?

This is the code to display the posts:

 <?php $categories = get_terms('categor', 'orderby=count&order=DESC&hide_empty=1');
 foreach( $categories as $category ):?>

<h2><?php echo $category->name; // Prints the cat/taxonomy group title ?></h2>
<?php $posts = get_posts(array(
         'post_type' => 'downloads',
         'taxonomy' => $category->taxonomy,
         'term' => $category->slug,
         'nopaging' => true,

foreach($posts as $post): 
 setup_postdata($post); //enables the_title(), the_content(), etc. without 
specifying a post ID ?>

<div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>

<div class="entry-content"> 

<h3><i class="icon-file"></i> <?php the_title(); ?></h3>

  <p><i class="icon-download-alt"></i> <a href="<?php the_field('file'); ?>"   
  target="_blank">Download file</a></br><?php the_field('discription'); ?></p>

<?php echo '<hr/>'; ?>

 </div><!-- .entry-content -->

 </div><!-- #post-## --> 
 <?php endforeach; ?>
share|improve this question
In code get_terms first parameter is 'categor' or 'category' ? – Ravinder Kumar May 23 '13 at 12:05
No typo there, its categor. – NielsPilon May 23 '13 at 12:11
are you saying an entirely different template file is loading? if that's the case, your issue has nothing to do with the contents of this template file. start by inspecting the global $wp_query and compare them between the two sites. – Milo May 23 '13 at 14:15

Check get_posts()

you code may be

$posts = get_posts(array(
         'post_type' => 'downloads',
         'tax_query' => array(
                'taxonomy' => $category->taxonomy,
                'field' => 'slug',
                'term' => $category->slug
share|improve this answer
Unfortunately that gives the same result; the archive page. – NielsPilon May 23 '13 at 12:32
I think, i forgot about 'field' => 'slug' in 'tax_query' in get_posts.try it and also check for get_posts() function link for more info given in answer – Ravinder Kumar May 23 '13 at 12:42
Same result unfortunately. – NielsPilon May 23 '13 at 13:07
your code seems to be good, enable WP_DEBUG in config file to see errors.check both foreach loop closes properly.use var_dump to check output types. – Ravinder Kumar May 23 '13 at 13:19

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.