Deprecated: Assigning the return value of new by reference is deprecated in /nfs/c03/h06/mnt/47169/domains/themehybrid.com/html/community/bb-settings.php on line 186

Deprecated: Assigning the return value of new by reference is deprecated in /nfs/c03/h06/mnt/47169/domains/themehybrid.com/html/community/bb-includes/backpress/functions.wp-object-cache.php on line 108

Deprecated: Assigning the return value of new by reference is deprecated in /nfs/c03/h06/mnt/47169/domains/themehybrid.com/html/community/bb-includes/backpress/pomo/mo.php on line 171

Deprecated: Assigning the return value of new by reference is deprecated in /nfs/c03/h06/mnt/47169/domains/themehybrid.com/html/community/bb-includes/functions.bb-l10n.php on line 484

Deprecated: Assigning the return value of new by reference is deprecated in /nfs/c03/h06/mnt/47169/domains/themehybrid.com/html/community/bb-includes/backpress/class.wp-taxonomy.php on line 581
Grouping Posts By a Meta Field in WordPress « Community

Welcome, guest!

Feel free to read the blog, browse for themes, or join the club.

The community forums are currently being phased out. At the end of February or early March 2012, you will no longer be able to post here. This is because the entire site is being restructured. Please use the main forums for discussions.

Grouping Posts By a Meta Field in WordPress

  1. I have created a custom post type in WordPress, and one of the fields is brewing company. I would like to be able to arrange the post by that field.

    Something like this:

    Brewing Company - Country
    Beer Name, Beer Type

    All of the fields are working properly, but I can't figure out how to create the correct loop. Here is my loop section for my beers page.

    <article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
            <header class="entry-header">
                    <h1 class="entry-title"><?php the_title(); ?></h1>
            </header><!-- .entry-header -->
    
            <div class="entry-content">
                    <?php the_content(); ?>
                    <?php query_posts( get_post_meta( $post->ID, 'Query', true )); ?>
                    <?php if ( have_posts() ) : ?>
    
                                                    <?php while ( have_posts() ); ?>
                                                            <ul><span class="brewing-company"><?php echo get_post_meta($post->ID, 'brewing_company', true); ?></span> - <?php echo get_post_meta($post->ID, 'brewing_country', true);?>
                                                                    <?php the_post();?>
                                                                    <li> <?php the_title(); ?>, <span class="beer-style"><?php echo get_post_meta($post->ID,'beer_style', true); ?></span></li>
                                                    <?php endwhile; ?>
                                                            </ul>
                                            <?php endif; wp_reset_query(); ?>
                    <?php wp_link_pages( array( 'before' => '<div class="page-link">' . __( 'Pages:', 'twentyeleven' ), 'after' => '</div>' ) ); ?>
                    <?php edit_post_link( __( 'Edit', 'twentyeleven' ), '<span class="edit-link">', '</span>' ); ?>
            </div><!-- .entry-content -->
    </article><!-- #post-<?php the_ID(); ?> -->

    The Query parameter comes from another meta value on the beers page. That is equal to post_type=beer&showposts=100&order_by=get_post_meta($post->ID, 'brewing_company', true).

    Any help would be greatly appreciated. You can see my current progress at http://drewclardy.com/beers

Topic Closed

This topic has been closed to new replies.

Topic Info

Topic Tags:

No tags yet.