我正在查询存档模板中的自定义帖子类型。每个帖子都附加了元值。该循环确实列出了每个帖子,但每个帖子上的元值都是从第一个帖子中提取的。所以,我有一个帖子列表,所有的元值都是相同的,数据保存在第一个帖子上。数据已正确保存在数据库中。这是我的循环:
$current_time = current_time('mysql');
list( $today_year, $today_month, $today_day, $hour, $minute, $second ) = split( '([^0-9])', $current_time );
$current_timestamp = $today_year . $today_month . $today_day . $hour . $minute;
$args = array( 'post_type' => 'event',
'order' => 'ASC',
'orderby' => 'meta_value_num',
'posts_per_page' => 20,
'meta_key' => '_start_eventtimestamp',
'meta_query' => array(
array(
'key' => '_start_eventtimestamp',
'value' => $current_timestamp,
'compare' => '>'
)
)
);
// Gets the event start month from the meta field
$month = get_post_meta( $post->ID, '_start_month', true );
// Converts the month number to the month name
//$month = $wp_locale->get_month_abbrev( $wp_locale->get_month( $month ) );
// Gets the event start day
$day = get_post_meta( $post->ID, '_start_day', true );
// Gets the event start year
$year = get_post_meta( $post->ID, '_start_year', true );
$numdays = get_post_meta( $post->ID, '_tour_numdays', true );
$price = get_post_meta( $post->ID, '_tour_price', true );
query_posts( $args );
while (have_posts() ) : the_post();
echo '<ul>';
echo '<li>' . $month . '/' . $day .'</li>';
echo '<li><a href="' . get_permalink() . '">' . get_the_title() . '</a></li>';
echo '<li>' . $numdays . '</li>';
echo '<li>' . $price . '</li>';
echo '<li><a href="#">Join this Trip</a></li>';
echo '</ul>';
endwhile;
我找不到解决方案。我尝试将查询从更改为WP_Query
,query_posts
但仍然没有运气。