Php 重新排序wordpress提要中的所有项目,包括开始和结束日期
我正在尝试对WordPress中的默认“yourdomainname.com/feed”项进行重新排序,以便在开始和结束日期元值之后进行排序 我有一些代码在模板中工作得很好,并且做前端。然而,当我在Php 重新排序wordpress提要中的所有项目,包括开始和结束日期,php,xml,wordpress,rss,feed,Php,Xml,Wordpress,Rss,Feed,我正在尝试对WordPress中的默认“yourdomainname.com/feed”项进行重新排序,以便在开始和结束日期元值之后进行排序 我有一些代码在模板中工作得很好,并且做前端。然而,当我在functions.php文件中插入几乎相同的代码时,提要仍然“未被触及” 有没有人能发现或指出我做错了什么?下面是我放在functions.php文件中的代码 /* Sort all posts to be ordered by meta start date. */ function f
functions.php
文件中插入几乎相同的代码时,提要仍然“未被触及”
有没有人能发现或指出我做错了什么?下面是我放在functions.php
文件中的代码
/*
Sort all posts to be ordered by meta start date.
*/
function feed_filter($query){
if($query->is_feed){
// Find todays date
$date = date('Ymd');
$query_args = array(
'meta_query' => array(
array(
'key' => 'end_date',
'compare' => '>=',
'value' => $date,
)
),
'meta_key' => 'start_date',
'orderby' => 'meta_value_num',
'order' => 'ASC'
);
debugIt($query_args);
$query->set( 'meta_query', $query_args );
}
}
add_action( 'pre_get_posts', 'feed_filter');
我通过创建自己的RSS提要模板解决了这个问题。这里有一个例子
<?php /* Template Name: Event RSS layout */ header("Content-type: text/xml"); echo '<?xml version="1.0" encoding="UTF-8" ?>'; ?>
<rss version="2.0">
<channel>
<?php
$date = date('Ymd');
$args = array(
'numberposts' => -1,
'meta_query' => array(
array(
'key' => 'end_date',
'compare' => '>=',
'value' => $date,
)
),
'meta_key' => 'start_date',
'orderby' => 'meta_value_num',
'order' => 'ASC'
);
$posts = get_posts($args);
foreach ($posts as $post){ setup_postdata($post);
$date = get_field('start_date');
$date = strftime("%A den %e. %B", strtotime($date));
?>
<item>
<title><?php echo $date; ?> - <?php the_title(); ?></title>
<link><?php the_permalink(); ?></link>
<guid><?php the_permalink(); ?></guid>
<description>
<![CDATA[
<img src="<?php the_post_thumbnail_url('thumbnail'); ?>" /><?php echo wp_trim_words( get_the_excerpt(), 40, '...' ); ?>]]>
</description>
<pubDate><?php echo date('r', strtotime(get_the_date())); ?></pubDate>
</item>
<?php } ?>
</channel>
</rss>
-
我已经更新了上面的代码,以接近我正在尝试做的事情。