我正在使用基础标签,我想从datepicker字段按YEAR排序我的自定义帖子。每个标签是一年(2016年2015年等)。当用户单击选项卡并显示时,将显示具有该事件日期元字段(acf datepicker字段)的所有自定义帖子,并在该选项卡内容中进行监听。但现在使用我的代码,它列出了自己的选项卡中的每个帖子,这些帖子会导致同一年的多个标签(2015-2015-2015-2016-2016)而不是(2016-2015-2014-2013),其中包含的帖子位于标签内容。这个例子就是我想要实现的目标:exactly what i am after
我不知道我现在在哪里,但是我已经做了很多事,没有做任何事情。从来没有做过这样的事情所以我可能是我的leage,但我想知道如何做到这一点以及我需要在代码中进行更改以完成它。到目前为止,这是我的代码:
$currentTime = current_time('Ymd'); // getting current time
$format_in = 'd/m/Y'; // the format your value is saved in (set in the field options)
$format_out_fields = 'Y'; // the format you want to end up with
$date = DateTime::createFromFormat($format_in, get_field('event_date'));
$args = array(
'post_type' => 'cpt',
'posts_per_page' => -1,
'orderby' => 'meta_value',
'meta_key' => 'acf_field',
'order' => 'DEC',
);
$subsQuery = new WP_Query( $args );
?>
<?php if ( $subsQuery->have_posts() ) : ?>
<?php section_open(); ?>
<h2 class="type2"><?php _e('H1 tabs', 'theme'); ?></h2>
<?php innerSection_open(); ?>
<?php ///////// TABS TITLE / BUTTONS ///////////// ?>
<ul class="tabs" data-tabs id="tabs">
<?php
$counter = 0;
while ( $subsQuery->have_posts() ) : $subsQuery->the_post();
++$counter;
$format_in = 'd/m/Y'; // the format your value is saved in (set in the field options)
$format_out = __('jS F Y', 'theme'); // the format you want to end up with
$date = DateTime::createFromFormat($format_in, get_field('acf_field'));
?>
<li class="tabs-title <?php if ( $counter == 1 ) { echo "is-active"; } ?>">
<a href="#panel-<?php the_ID(); ?>" <?php if ( $counter == 1 ) { echo 'aria-selected="true"'; } ?>>
<?php
$format_in = 'd/m/Y'; // the format your value is saved in (set in the field options)
$format_out_tabs = 'Y'; // the format you want to end up with
$date = DateTime::createFromFormat($format_in, get_field('acf_field'));
echo $date->format( $format_out_tabs );
?>
</a>
</li>
<?php endwhile; ?>
</ul>
<?php ///////// TABS CONTENT ///////////// ?>
<div class="tabs-content" data-tabs-content="tabs">
<?php
$counter = 0;
while ( $subsQuery->have_posts() ) : $subsQuery->the_post();
++$counter;
?>
<?php
$format_in = 'd/m/Y'; // the format your value is saved in (set in the field options)
$format_out = __('j.m.Y', 'theme'); // the format you want to end up with
$format_out_year = __('Y', 'theme'); // the format you want to end up with
$date = DateTime::createFromFormat($format_in, get_field('event_date'));
$date_year = DateTime::createFromFormat($format_in, get_field('event_date'));
?>
<div class="tabs-panel <?php if ( $counter == 1 ) { echo "is-active"; } ?>" id="panel-<?php the_ID(); ?>">
<span><?php echo $date->format( $format_out ); ?>:</span><br/>
<span class="bold">
<?php if( get_field( 'acf_type' ) == "event") { ?>
<?php _e('Event', 'theme'); ?>:
<?php } ?>
<?php
$theTitle = get_the_title();
echo $theTitle;
?>
</span><br/>
<?php if( get_field( 'link' )) { ?>
<?php if (isexternal(get_field('link')) == true ) { ?>
<a href="<?php the_field('event_link' ); ?>" target="_blank" style="text-decoration: underline;"><?php _e('Read more', 'theme'); ?> <i class="fa fa-external-link" aria-hidden="true"></i></a>
<?php } ?>
<?php } ?>
</div>
<?php endwhile; ?>
</div>