• I’ve got a theme that I’m using and it’s throwing posts up on a slider on my home page but I would like to order the way they show up. The code currently in place is:

    <?php
    //OptionTree Stuff
    if ( function_exists( 'get_option_tree') ) {
    	$theme_options = get_option('option_tree');
    	$homeCategory = get_option_tree('home_category',$theme_options);
    	$homeNumber = get_option_tree('home_number',$theme_options);
    }
    ?>
    
    	<?php
    	$temp = $wp_query;
    	$wp_query= null;
    	$wp_query = new WP_Query();
    	$wp_query->query('cat='. $homeCategory .'&showposts='. $homeNumber .''.'&paged='.$paged);
    	while ($wp_query->have_posts()) : $wp_query->the_post();
    	?>

    And the way I would like this to be ordered would be the following:

    orderby=meta_value&meta_key=event_date&order=ASC

    I’ve never used option tree before in obtaining information from some theme options, so I’m kind of confused on how I would integrate that ordering method with the other code. Any help is much appreciated, thanks!

    Jarth

Viewing 3 replies - 1 through 3 (of 3 total)
  • You just need to add your arguments to the query string:

    $wp_query->query('cat='. $homeCategory .'&showposts='. $homeNumber .''.'&paged='.$paged.'&orderby=meta_value&meta_key=event_date&order=ASC');

    Be sure your event_dates are stored with the year first, as in Y-m-d or Ymd format, or they won’t sort properly.

    Thread Starter jarth3000

    (@jarth3000)

    This didn’t work, just coming up with an error; I had already tried just placing at the end. Not sure what the deal is!

    Thread Starter jarth3000

    (@jarth3000)

    Never mind. I was being an idiot for about 2 seconds. Thanks vtxyzzy!

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Ordering Posts’ is closed to new replies.