Support » Fixing WordPress » Filter posts based on custom fields?

  • Resolved syrupcore

    (@syrupcore)


    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)
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Filter posts based on custom fields?’ is closed to new replies.