Orderby custom field contents
-
Hey Forum,
I’m trying to think of a way to sort my posts numerically via contents of one of my custom fields. The site is for an auction house who want to sort posts via lot number.
Below is the code I have so far – any help would be great:
`<!–<?php
query_posts(‘cat=4’);while (have_posts()) : the_post();
the_title();
the_content();
the_meta();
endwhile;?>
–><!– Start the Loop. –>
<?php if ( have_posts() ) : while ( have_posts() ) : the_post();// set up variables to hold custom field entries.
$subtitle = get_post_meta($post->ID, ‘subtitle’, true);
$lotnum = get_post_meta($post->ID, ‘lot_number’, true);
$description = get_post_meta($post->ID, ‘description’, true);
$estimate = get_post_meta($post->ID, ‘estimate’, true);
$auctiondate = get_post_meta($post->ID, ‘auction_date’, true);
$image = get_post_meta($post->ID, ‘image’, true);?><!– Display the Post’s Content in a div box. –>
<div class=”product-box”>
-
<li class=”title”>Title: <?php the_title();?>
- Lot Number: <?php echo $lotnum; ?>
- Description: <?php echo $description; ?>
- Guide Price: <?php echo $estimate; ?>
- Auction Date: <?php echo $auctiondate; ?>
- <?php echo $image; ?>
<li class=”subtitle”>Subtitle: <?php echo $subtitle; ?><!– Display our Custom Field –>
<li class=”galleryset”><?php the_content();?>
</div> <!– /product box –>
<!– Stop The Loop (but note the “else:” – see next line). –>
<?php endwhile; else: ?><!– The very first “if” tested to see if there were any Posts to –>
<!– display. This “else” part tells what do if there weren’t any. –>
<p>Our next auction catalogue will be published here shortly – please visit again soon</p><!– REALLY stop The Loop. –>
<?php endif; ?>
The topic ‘Orderby custom field contents’ is closed to new replies.