Wordpress RSS 提要中的递减日期



我必须在RSS提要的每个项目中从今天开始按递减顺序获取日期。提要中的帖子是通过 while 循环发送的。当我尝试获取日期时,它在每个项目中只显示一个值。这是我尝试过的

while ( $the_query->have_posts() ) {
$the_query->the_post();     
$post_id = get_the_ID();
$the_post = get_post($post_id);
$excerpt = $the_post->post_excerpt;
$modified = $the_post->post_modified;
$created = $the_post->post_date;
$author_id = $the_post->post_author;
$menu_order  = $the_post->menu_order;
$post_parent  = $the_post->post_parent;
$author =   get_the_author_meta('display_name', $author_id );               
$categories = get_the_category();
switch ($csrp_pubdate_date_format) {
case "rfc":
$today = date('Y-m-d'); 
for($i=1; $i<=4; $i++)
{
$repeat = strtotime("-1 day",strtotime($today));
$today = date('Y-m-d',$repeat);
$pub_date =  $today;
}
}//end while loop

我使用循环限制 4 只是为了测试目的。它必须是无限循环。

这就是我得到的

<item>
<title>
<![CDATA[
The Conundrum of Coffee &#8211; Natural Replacements
]]>
</title>
<pubDate>2019-08-05</pubDate>
</item>
<item>
<title>
<![CDATA[
The Conundrum of Coffee &#8211; Natural Replacements
]]>
<pubDate>2019-08-05</pubDate>
</item>

等等...

这就是我需要的

<item>
<title>
<![CDATA[
The Conundrum of Coffee &#8211; Natural Replacements
]]>
</title>
<pubDate>2019-08-09</pubDate>
</item>
<item>
<title>
<![CDATA[
The Conundrum of Coffee &#8211; Natural Replacements
]]>
<pubDate>2019-08-08</pubDate>
</item>
<item>
<title>
<![CDATA[
The Conundrum of Coffee &#8211; Natural Replacements
]]>
</title>
<pubDate>2019-08-07</pubDate>
</item>
<item>
<title>
<![CDATA[
The Conundrum of Coffee &#8211; Natural Replacements
]]>
<pubDate>2019-08-06</pubDate>
</item>

有人可以帮我实现这一目标吗

Please use in your $the_query 

$args = array(
'post_type' => 'post',
'orderby'   => 'date',
'order' => 'DESC',
'posts_per_page' => -1
);
$the_query = new WP_Query($args);
while ( $the_query->have_posts() ) {
$the_query->the_post();     
$post_id = get_the_ID();
$the_post = get_post($post_id);
$excerpt = $the_post->post_excerpt;
$modified = $the_post->post_modified;
$created = $the_post->post_date;
$author_id = $the_post->post_author;
$menu_order  = $the_post->menu_order;
$post_parent  = $the_post->post_parent;
$author =   get_the_author_meta('display_name', $author_id ); 
}//end while loop
check with this. Is that you looking for or get_the_category() ?

最新更新