• Using this great plugin is it possible to sort by one of my custom meta_values.
    eg. I have a custom meta which displays the price, how do I sort in my query to display based on this price.
    This is my current state, meta_key => price_low being the name of the field I’d like to base my sort. This set up below doesn’t work unfortunately.

    <?php
      $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
      $post_per_page = 12; // -1 shows all posts
      $args=array(
        'post_type' => 'accommodations',
        'community' => 'central-area',
        'paged' => $paged,
        'posts_per_page' => $post_per_page,
        'meta_key' => 'price_low',
        'orderby'=> 'ASC'
      );
      $temp = $wp_query;  // assign orginal query to temp variable for later use
      $wp_query = null;
      $wp_query = new WP_Query($args);
      if( have_posts() ) :?>

    Many thanks in advance.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Start with setting the orderby value properly.

    'orderby'=> 'ASC'

    ASC is applicable to the order parameter, which chooses the direction to order in.

    Set orderby to meta_value or meta_key, and order to either ASC or DESC.

    If you are indeed referring to the WPAlchemy code, read the following, wpalchemy meta box storage article, I will be soon revising the code to make this aspect of interaction much easier for end users.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘WP Alchemy’ is closed to new replies.