I have a wordpress category archive for posts in the "press" category. Each category post is currently sorted by the WordPress publish date. Right now each post also has a " Press Date " field which lets the user post a date in a month year format like "May 2012"
I would like to sort the posts based on this Press Date instead. Here is my current code:
<?php query_posts('showposts=10000&cat=3'); if ( have_posts() ) : ?>
<?php while ( have_posts() ) : the_post(); ?>
<? $count = $count + 1; $clear = $count % 6; ?>
<a <? post_class("press-block"); ?> href="<? echo get('link');?>" target="_blank">
<? echo get_image ('press_image') ?>
<span class="press-info">
<? the_title(); ?>
<span><? echo get('publication_title'); ?></span>
<span><? echo get('press_date');?></span>
</span>
</a>
<?php endwhile; ?>
<?php else : ?>
No Posts Found
<?php endif; wp_reset_query(); ?>
To use custom fields/meta values to order the query_posts result
you can use
query_posts('showposts=10000&cat=3&orderby=meta_value&meta_key=press_date'); // name of 'Press Date' field
For more see Order & Orderby Parameters .
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.