Sort posts in category by custom field
-
Hi all,
I’d like to be able to allow end users to determine the order in which posts are displayed, particularly when using the category template, by adding a custom field, Order, which has a value of A, B, C etc etc.
The following code works just fine, but would need to be manually altered each time the user wanted a new category:
<?php $the_query = new WP_query( array ( 'category_name' => 'test', 'orderby' => 'meta_value', 'meta_key' => 'Order', 'order' => 'ASC' ) ); while ($the_query->have_posts()) : $the_query->the_post(); get_template_part( 'content_issue_summary', get_post_format() ); endwhile; wp_reset_query(); ?>
I’ve been trying to alter the category template such that I can create a variable called $cat_name and give it the value of single_cat_title(), then use that to replace ‘test’ – but it’s not working. Any suggestions?
- The topic ‘Sort posts in category by custom field’ is closed to new replies.