Title: While loop in Foreach Loop
Last modified: August 20, 2016

---

# While loop in Foreach Loop

 *  Resolved [AngelEyes](https://wordpress.org/support/users/clustervision/)
 * (@clustervision)
 * [14 years, 3 months ago](https://wordpress.org/support/topic/while-loop-in-foreach-loop/)
 * Im working a portfolio website and for some reason this PHP isn’t working for
   me.
    The site is basically a one pager, and I need to loop through each category
   within a custom post type (Portfolio) which is working, but my WP query that 
   goes through each category isn’t working for some reason. Anyone have insight?
 * thanks!

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

 *  Thread Starter [AngelEyes](https://wordpress.org/support/users/clustervision/)
 * (@clustervision)
 * [14 years, 3 months ago](https://wordpress.org/support/topic/while-loop-in-foreach-loop/#post-2535988)
 * Also, I should note that I did a print_r($the_query); and it returned all the
   stuff you would expect, so it seems to be specifically the while loop that isn’t
   working for some reason.
 * Its also not an issue with my custom field, because I tried echoing out some 
   random text inside the loop and that didnt work.
 *  Thread Starter [AngelEyes](https://wordpress.org/support/users/clustervision/)
 * (@clustervision)
 * [14 years, 3 months ago](https://wordpress.org/support/topic/while-loop-in-foreach-loop/#post-2535989)
 * Figured it out. Had to add the post type to the query.

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

The topic ‘While loop in Foreach Loop’ is closed to new replies.

## Tags

 * [custom post](https://wordpress.org/support/topic-tag/custom-post/)
 * [loops](https://wordpress.org/support/topic-tag/loops/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 2 replies
 * 1 participant
 * Last reply from: [AngelEyes](https://wordpress.org/support/users/clustervision/)
 * Last activity: [14 years, 3 months ago](https://wordpress.org/support/topic/while-loop-in-foreach-loop/#post-2535989)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
