Wordpress the_field();转换为数字

时间:2016-01-23 19:11:14

标签: php wordpress string

  $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只返回字符串。有没有办法将其转换为数字?

1 个答案:

答案 0 :(得分: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.

希望它有所帮助。