Help w/query to order by custom field subset
-
I’m working on a new website for my labgroup at work (https://www.orcatech.org/wordpress for now) and am having some trouble sorting a subset of posts by a custom field.
What I want to happen is:
If a study is currently active, it should show up on the front page sorted by start_date.Current state:
Able to pull from the study category and get only the active studies. Unable to sort properly.Here’s the code I’m using:
<h2>Current Studies</h2> <dl class="dp_columnlisting"> <?php query_posts('category_name=studies&orderby=start_date'); $current_year = date('Y');?> <?php while (have_posts()) : the_post(); ?> <?php $start_date=get_post_meta($post->ID, "start_date", true); $end_date=get_post_meta($post->ID, "end_date", true); ?> <? if ($start_date <= $current_year && $end_date >= $current_year){?> <!-- Display the title as a link to the post's permalink --> <dt><?php echo $start_date; ?> - <?php echo $end_date; ?></dt><dd><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></dd> <?php } ?> <?php endwhile;?>
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘Help w/query to order by custom field subset’ is closed to new replies.