2016-01-23 47 views
0
$query = new WP_Query($args); 
    while ($query -> have_posts()) : $query -> the_post(); ?> 
    <tr> 
     <td><?php the_field('home_player'); ?></td> 
     <td><?php displayresult(the_field('result')); ?></td> 
     <td><?php the_field('away_player'); ?></td> 
     <td><?php date('dS F Y', the_field('date')); ?></td> 
     <td><?php the_field('board'); ?></td> 
    </tr> 
    <?php endwhile; ?> 

这是我正在处理的代码。我将日期存储为时间戳,我试图在php中使用日期函数进行转换。正如写这篇文章,它发生在我身上,它可能是一个字符串,而不是数字。我测试了它,结果the_field只返回字符串。有什么办法将它转换为数字吗?Wordpress the_field();转换为数字

+0

之前有人问我试过“the_field('date')+ 0” –

+0

通过时间戳你的意思是一个unix时间戳,一个数值例如'1453577004',只有你有它的字符串形式,''1453577004'' ?你不需要将它转换为数字以将它作为第二个参数传递给'date'函数 - PHP的自动类型转换将处理该数据。 – CBroe

+0

你的意思是[strtotime](http://php.net/manual/en/function.strtotime.php)? –

回答

0

我知道我很晚了。但我只是发现了这个帖子。你可以这样做。

<td><?php date('dS F Y', strtotime(the_field('date'))); ?></td> // strtotime will convert it from string to time and then date can do its magic. 

希望它有助于某人。