sorting custom posts by title not working
-
Hello – I have a really simple problem that I can’t seem to find the fix for. I’m trying to sort my custom posts (for a list of red wines) by title so that they display in alphabetical order, and they refuse to sort in any way except publish date. Here’s my query:
<?php $args = array( 'menu-item-type' => 'wine red glass', 'post_type' => 'food_and_drinks', 'post_status' => 'publish', 'posts_per_page' => -1, 'caller_get_posts' => 1, 'orderby' => 'title', 'order' => 'ASC' ); $my_query = null; $my_query = new WP_Query($args); if ( $my_query->have_posts() ) { ?> <?php print '<h4>Red</h4>'; ?> <div class="results"> <?php while ($my_query->have_posts()) : $my_query->the_post(); ?> <div class="menu-item"> <?php $price = get_post_meta($post->ID, 'price', false); ?> <?php the_title(); ?> <?php print '— ' . $price[0]; ?> <?php the_excerpt(); ?> </div> <?php endwhile; ?> </div> <?php } wp_reset_query(); ?>The results from the above query display like this:
Cabernet Sauvignon — 8/32
Pascual Toso, Mendoza, Argentina 200Pinot Noir — 8/32
Domaine des Salices, Francois Lurton, Languedoc 200Merlot — 8/32
Independent Producers, Washington 2008Pinot Noir — 10/40
Cote Chalonnaise, Vignerons de Buxy, Burgundy 2008Just in case it’s helpful, here’s my code where I’m registering the custom post type in functions.php:
register_post_type('food_and_drinks', array( 'label' => __('Food & Drinks'), 'singular_label' => __('Food & Drink'), 'public' => true, 'show_ui' => true, 'capability_type' => 'post', 'hierarchical' => false, 'rewrite' => false, 'query_var' => false, 'supports' => array('title', 'editor', 'author', 'custom-fields') ));Any ideas? I’m probably missing something pretty simple.
Thanks!
The topic ‘sorting custom posts by title not working’ is closed to new replies.