douyi2798 2017-07-30 19:19
浏览 52
已采纳

Wordpress get_the_date()仅检索帖子ID

I have created a loop of posts in my wp homepage where 5 recent posts are shown one below the other. The code to loop wp data is

$args = array('numberposts'=>'5');
$recentposts = wp_get_recent_posts($args);  
foreach($recentposts as $post){
    $v = $post['ID'];
    echo 'Title:'.get_the_title($v).'<br>';
    echo 'Date:' .get_the_date($v).'<br>';
}

The Title section works perfectly, but Date section only shows the ID of the post and nothing else.

What am I doing wrong?

  • 写回答

2条回答 默认 最新

  • douhuan2101 2017-07-30 19:22
    关注

    Look at the documentation : https://codex.wordpress.org/Function_Reference/get_the_date

    First parameters is format, second is ID, so :

    // whatever your format
    get_the_date('Y-m-d', $v)
    

    To get your default Wordpress site date format :

    $date_format = get_option( 'date_format' );
    get_the_date( $date_format, $post_id );
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 用hfss做微带贴片阵列天线的时候分析设置有问题
  • ¥50 我撰写的python爬虫爬不了 要爬的网址有反爬机制
  • ¥15 Centos / PETSc / PETGEM
  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥120 计算机网络的新校区组网设计
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 海浪数据 南海地区海况数据,波浪数据
  • ¥20 软件测试决策法疑问求解答
  • ¥15 win11 23H2删除推荐的项目,支持注册表等