WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Filter posts based on custom fields? (3 posts)

  1. syrupcore
    Member
    Posted 5 years ago #

    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

  2. MichaelH
    Member
    Posted 5 years ago #

    Otto's response on this thread is pretty slick:
    http://wordpress.org/support/topic/209558?replies=4#post-873550

  3. syrupcore
    Member
    Posted 5 years ago #

    Thank you! that is the radness. yay 2.6.2!

Topic Closed

This topic has been closed to new replies.

About this Topic