我曾获得以下功能的帮助:
function get_event_list( $latest = true, $order = \'ASC\', $return = false ) {
$yesterday = time() - 24*60*60;
$compare = $latest ? \'>\' : \'<\';
$current_year = \'\';
$args = array(
\'post_type\' => \'wr_event\',
//\'posts_per_page\' => is_archive() ? 16 : -1,
\'posts_per_page\' => -1,
\'meta_key\' => \'event_date\',
\'orderby\' => \'meta_value_num\',
\'order\' => $order,
\'meta_value\' => $yesterday,
\'meta_compare\' => $compare,
/*\'tax_query\' => array(
array(
\'taxonomy\' => \'event_type\',
\'field\' => \'slug\',
\'terms\' => \'empfehlungen\',
\'operator\' => \'NOT IN\'
),
)*/
);
$loop = new WP_Query( $args );
// if function should not return any posts
if ( $loop->have_posts() && $return ) return true;
echo \'<ul class="event-items">\';
while ( $loop->have_posts() ) : $loop->the_post();
global $post;
$this_year = get_post_meta( $post->ID, \'event_date\', true );
$this_year = date(\'Y\', (int)$this_year);
if ( !$latest && ( $this_year != $current_year ) ) :
if ($current_year != \'\') echo \'</ul></li>\';
echo \'<li class="year y\'.$this_year.\'"><div class="wrapper year-count"><h2>\' . $this_year . \'</h2><a class="load-year" href="#">Archiv anzeigen</a></div><ul>\';
$current_year = $this_year;
endif;
get_template_part( \'inc/event\', \'item\' );
endwhile;
if ($current_year != \'\') echo \'</ul></li>\';
wp_reset_postdata();
echo \'</ul>\';
}
我遇到的问题是,此函数将获取所有比当前年份更早的事件。
我如何转换这个函数,以便添加一个参数,无论我经过哪一年都可以得到我?
我的目标是,我不想一次加载所有事件,而是在单击“2011”时,我想通过ajax检索这些事件。
有人能帮我吗?
提前谢谢你,马特
最合适的回答,由SO网友:shahpranaf 整理而成
我\'五、E MoD我F我ED A.Bo五、E FUNCT我oN soMEWHA.T十、A.;十、A.;FUNCT我oN GET_E五、ENT_L我sT( $LA.TEsT = TRUE, $oRDER = \'A.sC\', $RETURN = FA.LsE, $YEA.R ) {十、A.; // PA.ss YEA.R 我.E $YEA.R十、A.; $ENDDA.TE = sTRToT我ME($YEA.R.“”-1.2.-3.1.“”); // YEA.R\'s LA.sT DA.TE十、A.; $sTA.RTDA.TE = sTRToT我ME( ($YEA.R-1.).“”-1.2.-3.1.“”); YEA.R\'s F我RsT DA.TE
十、A.;十、A.;
$yesterday = array($startdate, $enddate ); // Fetch posts between these dates
$compare = \'BETWEEN\';// Between above two dates
$current_year = \'\';
$args = array(
\'post_type\' => \'wr_event\',
//\'posts_per_page\' => is_archive() ? 16 : -1,
\'posts_per_page\' => -1,
\'meta_key\' => \'event_date\',
\'orderby\' => \'meta_value_num\',
\'order\' => $order,
\'meta_value\' => $yesterday,
\'meta_compare\' => $compare,
/*\'tax_query\' => array(
array(
\'taxonomy\' => \'event_type\',
\'field\' => \'slug\',
\'terms\' => \'empfehlungen\',
\'operator\' => \'NOT IN\'
),
)*/
);
$loop = new WP_Query( $args );
十、A.;十、A.;
十、A.;十、A.;
我Ts UNTEsTED BUT sHoULD WoRK. LET ME KNoW 我F 我T WoRKED oR NoT
十、A.;