Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I made a post recently that did not explained myself right! Come again, but with better explanations.

I need the "Select Option" change the order of query_posts. My current code is:

    <option selected="selected">Select order of posts</option>
    <option>Highest price</option><!-- hypercart_meta_price  "order=DESC" -->
    <option>lowest price</option><!-- hypercart_meta_price  "order=ASC" -->
    <option>Discount in%</option><!-- hypercart_meta_discount  "order=DESC" -->
    <option>Release Date</option><!-- date  "order=DESC" -->
<?php $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; ?>
<?php query_posts( 'post_type=products&orderby=meta_value_num&order=DESC&meta_key=hypercart_meta_discount&key=price&cat=' .get_query_var('cat')."&paged=".$paged); ?>
<?php get_template_part("loop-products"); ?>

I just need to know how to change the query_posts using the "Select box" Thank you for understanding. Hug!

UPDATED MY ISSUE, sorry for the inconvenience.

share|improve this question
Rudimentary English is fine, but you'll have to add more information, if you want to be able to get a satisfying answer. Show some code - that's universal language anyway. –  Johannes Pille May 3 '13 at 15:13
Friend, see if you can understand: pastebin.com/F7g6LTSm –  Raank May 3 '13 at 15:29
This is actually a fairly complex question, with several steps to accomplish (register a query arg, add a query var via user input, and filter the query based on the user-input query var). What have you tried (add actual code to your question), what works, and what doesn't? –  Chip Bennett May 3 '13 at 17:50
s_ha_dum Updated my friend! –  Raank May 3 '13 at 17:50
Note: any solution using query_posts() is inherently incorrect. Please attempt an implementation that properly filters the default query via pre_get_posts. –  Chip Bennett May 3 '13 at 17:52
show 3 more comments

1 Answer

Your question is not very detailed. It is hard to work out exactly what you are doing but I am assuming that you are trying to sort posts by a custom meta meta_key/meta_value. This the formula for that (annotated but basically lifted from the Codex):

 $args = array(
   'post_type' => 'your_post_type', // I don't know what this is
   'meta_key' => 'your_key', // I don't know what this is
   'orderby' => 'meta_value_num', // only for numbers; use "meta_value" for alphanumerical keys
   'order' => 'ASC',
   'meta_query' => array(
           'key' => 'your_key',
           'value' => array('your_value'), // can be more than one
           'compare' => 'IN', // see the Codex for other values
 $query = new WP_Query($args);



share|improve this answer
Yes, sorry for not explaining right An example, the customer selects "High Value" messages appear "higher price" and so with the other options. I'm trying to solve this day ... :/ –  Raank May 3 '13 at 14:58
I think this answer still applies. –  s_ha_dum May 3 '13 at 15:08
Here is an example of the code I have: pastebin.com/F7g6LTSm –  Raank May 3 '13 at 15:26
add comment

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.