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.

This is similar to another question I asked, but I can't recognize how this query string works.

I have a custom field called "category_order" and I would like to sort my category page by this order (and not the date).

Here is my code:

<?php wp_reset_query(); ?>
    <div id="content">

    <div id="postFuncs">
      <div id="funcStyler"><a href="#" class="switch_thumb"></a></div>
          <?php if (is_category()) { 
           $cat_ID = get_query_var('cat'); ?>

          <?php echo '<h2>'; wpzoom_breadcrumbs(); echo'</h2>'; ?><?php } 
            elseif (!is_category() && !is_home()) { ?>
            <?php echo '<h2>'; wpzoom_breadcrumbs(); echo'</h2>'; ?>
            <?php }
            else { ?>
            <h2>Recent Videos</h2>
            <?php } ?>
    </div><!-- end #postFuncs -->

    <div id="archive">

    <?php if (have_posts()) : ?>
        <ul class="posts posts-3 grid">
            <?php  
      $i = 0;  
                while (have_posts()) : the_post();
                $i++;
            ?>
share|improve this question

1 Answer 1

up vote 1 down vote accepted

I added the query_posts so we can tell Wordpress of a modified query to run.
$query_string will let us add onto the current parameters.
orderby, meta_key, order let us define the query by telling it how to sort the results
More information on ordering by parameters

<?php wp_reset_query(); ?>
<div id="content">

  <div id="postFuncs">
    <div id="funcStyler"><a href="#" class="switch_thumb"></a></div>
    <?php if (is_category()) { 
      $cat_ID = get_query_var('cat'); ?>
      <h2><?php wpzoom_breadcrumbs(); ?></h2>
    <?php } elseif (!is_category() && !is_home()) { ?>
      <h2><?php wpzoom_breadcrumbs(); ?></h2>
    <?php } else { ?>
      <h2>Recent Videos</h2>
    <?php } ?>
  </div><!-- end #postFuncs -->

  <div id="archive">

    <?php global $query_string;
    query_posts( $query_string . '&orderby=meta_value_num&meta_key=your_custom_field"&order=ASC');
    if (have_posts()) : ?>
    <ul class="posts posts-3 grid">
    <?php $i = 0;  
    while (have_posts()) : the_post();
      $i++;
    ?>
share|improve this answer

Your Answer

 
discard

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.