Title: WordPress Custom Loop
Last modified: August 20, 2016

---

# WordPress Custom Loop

 *  [arav369](https://wordpress.org/support/users/arav369/)
 * (@arav369)
 * [13 years, 3 months ago](https://wordpress.org/support/topic/wordpress-custom-loop/)
 * I have to create a loop of the top 5 posts falling under any 1 or more of a set
   of categories. I have browsed the support forums and tried out all combinations.
   It is not working for me.
 * One odd output I got was that posts 2,4,6,8,10 that were falling under any 1 
   or more of the set of categories were displayed. Instead of the top 5 posts (
   1,2,3,4,5). The loop was skipping every alternate post.The code I used was as
   follows:
 *     ```
       query_posts('category_name=cat1,cat2');
       $ctr=1; while (have_posts() && $ctr<6) : the_post(); { $ctr++ ?>
       ---
       ---
       }?>
       ```
   
 * Please provide the code for achieving this custom loop.
 * Thanks in advance.

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

 *  [Michael](https://wordpress.org/support/users/alchymyth/)
 * (@alchymyth)
 * [13 years, 3 months ago](https://wordpress.org/support/topic/wordpress-custom-loop/#post-3273096)
 * please post the **full **code of the loop.
 * review:
    [http://codex.wordpress.org/The_Loop](http://codex.wordpress.org/The_Loop)
   [http://codex.wordpress.org/Class_Reference/WP_Query#Parameters](http://codex.wordpress.org/Class_Reference/WP_Query#Parameters)
   and particular the ‘posts_per_page’ parameter [http://codex.wordpress.org/Class_Reference/WP_Query#Pagination_Parameters](http://codex.wordpress.org/Class_Reference/WP_Query#Pagination_Parameters)
 *  [deepbevel](https://wordpress.org/support/users/deepbevel/)
 * (@deepbevel)
 * [13 years, 3 months ago](https://wordpress.org/support/topic/wordpress-custom-loop/#post-3273102)
 * I spent an hour with this last night, checked Sweepers references and more…stumped.
   Sorry I don’t remember the codes I tried but I felt I wasn’t even close, gettting
   no output.
 * I’ve always wanted to do this too, tried before and gave up. I’ve always had 
   to use multiple loops..
 *  [deepbevel](https://wordpress.org/support/users/deepbevel/)
 * (@deepbevel)
 * [13 years, 3 months ago](https://wordpress.org/support/topic/wordpress-custom-loop/#post-3273107)
 * [http://wordpress.org/support/topic/categoryphp-post_types-divided-per-category?replies=4#post-3579879](http://wordpress.org/support/topic/categoryphp-post_types-divided-per-category?replies=4#post-3579879)

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

The topic ‘WordPress Custom Loop’ is closed to new replies.

## Tags

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

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 3 replies
 * 3 participants
 * Last reply from: [deepbevel](https://wordpress.org/support/users/deepbevel/)
 * Last activity: [13 years, 3 months ago](https://wordpress.org/support/topic/wordpress-custom-loop/#post-3273107)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
