我找到了一个解决方案,它可以显示按日期值排序的帖子,还可以删除过去的帖子。
<div class="container">
<div class="row">
<table>
<tr>
<th>Artista</th>
<th>Fecha</th>
<th>Ciudad</th>
<th>Información</th>
</tr>
<?php
$today = current_time(\'Ymd\');
$args = array(
\'post_type\' => \'evento\',
\'post_status\' => \'publish\',
\'posts_per_page\' => \'-1\',
\'meta_query\' => array(
array(
\'key\' => \'fecha_del_evento\',
\'compare\' => \'>=\',
\'value\' => $today,
)
),
\'meta_key\' => \'fecha_del_evento\',
\'orderby\' => \'meta_value\',
\'order\' => \'ASC\',
);
$query = new WP_Query($args);
if ($query->have_posts()) :
while ($query->have_posts()) : $query->the_post();
?>
<?php $i = 0;?>
<?php if($i == 0){ echo "<tr>"; }?>
<td><?php the_title(); ?></td>
<?php $i++;?>
<td><?php the_field(\'fecha_del_evento\'); ?></td>
<?php $i++;?>
<td><?php the_field(\'lugar_del_evento\'); ?></td>
<?php $i++;?>
<td><?php echo get_the_content(); ?></td>
<?php $i++;?>
<?php if($i == 4){ echo "</tr>"; $i=0;}?>
<?php endwhile; ?>
<?php if($i < 4) echo \'</tr>\'; ?>
</table>
<?php wp_reset_postdata(); ?>
<?php endif; ?>
</div><!-- END OF ROW -->
</div><!-- END OF CONTAINER -->
请注意,此代码(当然在适当的查询中)足以按日期排序帖子:
\'meta_key\' => \'fecha_del_evento\',
\'orderby\' => \'meta_value\',
\'order\' => \'ASC\',
);