Title: Codex example not working
Last modified: August 19, 2016

---

# Codex example not working

 *  Resolved [tstruyf](https://wordpress.org/support/users/tstruyf/)
 * (@tstruyf)
 * [16 years, 9 months ago](https://wordpress.org/support/topic/codex-example-not-working/)
 * hi,
 * I’m trying to select all posts from one category. I do this multiple times one
   a page. So the codex says I need to make a new object:
 * (from: [the codex](http://codex.wordpress.org/The_Loop#Multiple_Loops))
 *     ```
       <?php $my_query = new WP_Query('category_name=special_cat&showposts=10'); ?>
   
       <?php while ($my_query->have_posts()) : $my_query->the_post(); ?>
         <!-- Do special_cat stuff... -->
       <?php endwhile; ?>
       ```
   
 * I made a category named special_cat en I tried to replace ‘special_cat’ with 
   an existing category…, but the array always return empty!
 * Anyone has the same problem?

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

 *  [Mark / t31os](https://wordpress.org/support/users/t31os_/)
 * (@t31os_)
 * [16 years, 9 months ago](https://wordpress.org/support/topic/codex-example-not-working/#post-1191910)
 * What have you put in place of..
 *     ```
       <!-- Do special_cat stuff... -->
       ```
   
 * If you havn’t replaced that with anything then you won’t get anything.. that’s
   to be expected..
 * If you’re simpy giving an example above and you’re saying the query is returning
   an empty result, does removing the category parameter then yield results?
 * If it does, then i’d guess there’s a problem with the name (category_name parameter
   is case sensitive iirc).
 * Try a simple cat name like Test or test, then create 1 test post in that cat 
   and give it a try in your query above.
 * Process of elimination..
 *  Thread Starter [tstruyf](https://wordpress.org/support/users/tstruyf/)
 * (@tstruyf)
 * [16 years, 9 months ago](https://wordpress.org/support/topic/codex-example-not-working/#post-1191918)
 * offcourse I replaced <!– Do special_cat stuff… –>
 * my exact code now:
 *     ```
       <?php $my_query = new WP_Query('showposts=1'); ?>
   
       <?php while ($my_query->have_posts()) : $my_query->the_post(); ?>
       <p>hello world</p>
       <?php endwhile; ?>
       ```
   
 * The output is 3 times “hello world”. I have a total of 7 post.
    Why 3? To me 
   it’s a total mystery!
 *  [Mark / t31os](https://wordpress.org/support/users/t31os_/)
 * (@t31os_)
 * [16 years, 9 months ago](https://wordpress.org/support/topic/codex-example-not-working/#post-1191930)
 * It should be 1, since you have showposts=1 …
 * You shouldn’t be placing this inside an existing loop, else you’ll get this result
   for an equal amount of times to the current loop..
 * If the existing loop has 3 matches, and runs the above code each time, you’ll
   get hello world that amount of times.
 *  Thread Starter [tstruyf](https://wordpress.org/support/users/tstruyf/)
 * (@tstruyf)
 * [16 years, 9 months ago](https://wordpress.org/support/topic/codex-example-not-working/#post-1191945)
 * no, here my total page code
 *     ```
       <?php
       /**
        * Template: Index.php
       */
   
       get_header();
       ?>
   
       <div class="inhoudcontainer"> 				
   
       			<?php $my_query = new WP_Query('category_name=news'); ?>
   
       			<?php while ($my_query->have_posts()) : $my_query->the_post(); ?>
       			  <?php the_title()?>
       			  <br /><br />
       			<?php endwhile; ?>
   
       </div> <!-- END INHOUDCONTAINER-->
   
       <?php get_footer(); ?>
       ```
   
 * I have a category calles news
 *  [Mark / t31os](https://wordpress.org/support/users/t31os_/)
 * (@t31os_)
 * [16 years, 9 months ago](https://wordpress.org/support/topic/codex-example-not-working/#post-1191954)
 * Are you using this as a template file?
 * If this a template file, and the file is named index.php, and also resides in
   your theme folder, you’ll end up with a conflict, since index.php is a reserved
   name for the root file of the theme.
 * Do you need this file for attaching to pages? because that’s what “Page Templates”
   are for, which is what the top most “Template:” does, to denote that it is a 
   Page Template file.
 * If you’re attaching this to a page, no problem there, i just think if you’re 
   naming it index.php the file will be having a conflict of interest.
 * Template names also shouldn’t read like this.
 *     ```
       * Template: Index.php
       ```
   
 * but like so…
 *     ```
       * Template: filename
       ```
   
 * without the extension (although the file must be a PHP file).
 *  Thread Starter [tstruyf](https://wordpress.org/support/users/tstruyf/)
 * (@tstruyf)
 * [16 years, 9 months ago](https://wordpress.org/support/topic/codex-example-not-working/#post-1191971)
 * I copied my theme to another Worpress 2.8.4 installation and it worked fine!
 * So I installed wordpress allover on my localhost and the code works !!
 * still, many thanks for your help !
 *  [Mark / t31os](https://wordpress.org/support/users/t31os_/)
 * (@t31os_)
 * [16 years, 9 months ago](https://wordpress.org/support/topic/codex-example-not-working/#post-1192051)
 * 🙂 Good stuff…
 * Mark resolved if all is ok (just to the right of the post).. —->

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

The topic ‘Codex example not working’ is closed to new replies.

## Tags

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

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 7 replies
 * 2 participants
 * Last reply from: [Mark / t31os](https://wordpress.org/support/users/t31os_/)
 * Last activity: [16 years, 9 months ago](https://wordpress.org/support/topic/codex-example-not-working/#post-1192051)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
