1

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

1 Answer 1

2

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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