Need help sorting posts from query_posts using meta_key and meta_value
-
I’m creating a theme with the option to create an online store. One option that needs to be included is a sort feature (i.e. priced low to high, high to low, a-z, etc.). The following code is what I worked up:
<?php // Let's start by checking the URL for variables $page = $_GET['sort']; // Let's sort the store posts if ($page == false) {} elseif ($page == 'low-to-high') { query_posts('meta_key=price&meta_value=&order=ASC&cat=' . $category_id); } elseif ($page == 'high-to-low') { query_posts('meta_key=price&meta_value=&order=DESC&cat=' . $category_id); } elseif ($page == 'a-z') { query_posts('orderby=title&meta_value=&order=ASC&cat=' . $category_id); } elseif ($page == 'z-a') { query_posts('orderby=title&meta_value=&order=DESC&cat=' . $category_id); } // The Loop if(have_posts()): while(have_posts()): the_post(); ?> <div id="post-<?php the_ID(); ?>" <?php post_class(); ?>> <a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php include(TEMPLATEPATH . '/thumb.php'); ?><span><?php the_title(); ?></span></a> <?php if(get_post_meta($post->ID, 'Price', true)) { echo '<div id="cat-price"><strong>Our Price:</strong> <span>' . get_post_meta($post->ID, 'Price', true) . '</span></div>'; } ?> <?php edit_post_link( 'Edit', '<span class="the-edit">', '</span>' ); ?> </div><!-- id="post-<?php the_ID(); ?>" --> <?php endwhile; else: endif; wp_reset_query(); ?>
It seems to be missing something because when i try to sort using the META_KEY and META_VALUE, the order is incorrect (the order to its own child-category is correct but not on the parent category).
I’m not sure if I’m explaining this correctly and hope someone understands and can help.
Basicly: If I try to order the posts by the meta_key and meta_value, the output is incorrect in out of order.
Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
- The topic ‘Need help sorting posts from query_posts using meta_key and meta_value’ is closed to new replies.