我遇到了一个问题,下面的代码按字母顺序给我一个asc顺序的帖子,我希望它在DATE按升序排列。我知道我必须使用usort()或asort(),但我不知道在哪里将它插入到这段代码中。
<?php
$query_date = custom_get_query_date_full(0);
global $more;
global $num_posts;
global $events_output;
$section_class = 'section';
$events_output = '';
if(!isset($num_posts)){
$num_posts = -1;
}
// no section given
$args = array(
'post_status'=>'publish',
'post_type'=> 'event',
'posts_per_page' => $num_posts,
'meta_key' => 'date',
'orderby' => 'meta_value',
'dateOrder' => 'ASC',
'meta_query' => array(
array('key' => 'date', 'value' => $query_date, 'compare' => '>' )
//,array('key' => 'page', 'value' => $post->ID, 'compare' => 'LIKE')
)
);
$s = 0;
$the_query = new WP_Query( $args );
if($the_query->post_count) {
echo "<ul>\n";
while ( $the_query->have_posts() ) : $the_query->the_post();
$alt_class = '';
if($s%2 != 0){
$alt_class = ' alt';
}
$s++;
if($s == $the_query->post_count){ $section_class = 'section-last';}
$day_not_set = get_field('day_not_set');
$date = get_field('date');
$day = substr($date,6,2);
$day_html = "<span class=\"time-day\">$day</span>";
if(substr($day,0,1)==0){
$day = substr($day,1,2);
}
$month = substr($date,4,2);
$year = substr($date,2,2);
$month = custom_get_month_string($month);
if(!empty($day_not_set)){
$day_html = "<span class=\"time-day\">20$year</span>";
}
$terms = get_the_terms( $post->ID, 'type' );
$terms_class = '';
foreach($terms as $term){
$terms_class .= "$term->slug ";
}
$events_output .= "
<li class=\"event-info $terms_class\">
<time>$month $day_html</time>
<h2><a href=\"" . get_permalink() . "\">" . get_the_title() . "</a></h2>" .
str_replace(' ','',trim(get_field('teaser'))). "
<div class=\"readmore\"><a href=\"" . get_permalink() . "\">View ></a></div>
</li> \n";
endwhile;
echo $events_output . "</ul>\n";
}
?>
<?php wp_reset_postdata();?>
答案 0 :(得分:0)
我认为是:
'orderby' => 'post_date',