drgbpq5930 2019-08-09 12:20
浏览 80

在Wordpress RSS提要中减少日期

I have to get date in decrement order starting from today in each item of RSS feed. Posts in feed are coming via while loop. And when I try to get date, it only displays one value in each item. This is what I have tried

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

I have used loop limit 4 just for testing purpose. It has to be infinite loop.

This is what I get

<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>

and so on......

This is what I require

<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>

Can someone please help me to achieve this

  • 写回答

1条回答

  • duanran6441 2019-08-09 12:32
    关注
    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() ?
    
    评论

报告相同问题?

悬赏问题

  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作