Sort category page with custom field

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).

Read More

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++;
            ?>

Related posts

Leave a Reply

1 comment

  1. 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++;
        ?>