Title: Filter posts based on custom fields?
Last modified: August 19, 2016

---

# Filter posts based on custom fields?

 *  Resolved [syrupcore](https://wordpress.org/support/users/syrupcore/)
 * (@syrupcore)
 * [17 years, 7 months ago](https://wordpress.org/support/topic/filter-posts-based-on-custom-fields/)
 * Hi,
 * I’m making an overview page that lists bits from a bunch of pages. bits = custom
   fields from each page. I need to output them in related groups. Each page has
   a custom field indicating which group it’s a part of (since pages can’t have 
   categories). I’m not sure how to filter my loop query by a custom field. Can 
   anyone help? Here’s my current loop.
 *     ```
       <?php $posts = get_posts( "static=true&posts_per_page=-1&child_of=2" ); ?>
   
       <?php if( $posts ) : ?>
       (some opening html)
       <?php foreach( $posts as $post ) : setup_postdata( $post ); ?>
       (do stuff)
       <?php endforeach; ?>
       <?php endif; ?>
       ```
   
 * Seems like the most elegant method to handle this would be an innerloop. In english:
   Get all the pages, for each group, loop over all of it’s pages. at the end of
   each group of pages, loop over the next group of pages. Sadly, not a clue how
   to actually do this! Well a clue, yes, but it ends there. 🙂
 * I’d be happy to just have mulitple separate loops or an inner series of if/elseifs.
 * Can anyone help me out?
 * Thanks for reading.
 * Will

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

 *  [MichaelH](https://wordpress.org/support/users/michaelh/)
 * (@michaelh)
 * [17 years, 7 months ago](https://wordpress.org/support/topic/filter-posts-based-on-custom-fields/#post-879372)
 * Otto’s response on this thread is pretty slick:
    [http://wordpress.org/support/topic/209558?replies=4#post-873550](http://wordpress.org/support/topic/209558?replies=4#post-873550)
 *  Thread Starter [syrupcore](https://wordpress.org/support/users/syrupcore/)
 * (@syrupcore)
 * [17 years, 7 months ago](https://wordpress.org/support/topic/filter-posts-based-on-custom-fields/#post-879421)
 * Thank you! that is the radness. yay 2.6.2!

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

The topic ‘Filter posts based on custom fields?’ is closed to new replies.

## Tags

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

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 2 replies
 * 2 participants
 * Last reply from: [syrupcore](https://wordpress.org/support/users/syrupcore/)
 * Last activity: [17 years, 7 months ago](https://wordpress.org/support/topic/filter-posts-based-on-custom-fields/#post-879421)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
