【发布时间】:2021-08-28 02:13:37
【问题描述】:
我需要获取 ACF 字段的元值。
名为“submitdate”的 ACF 字段(格式 => 日期时间选择器:Y-m-d H:i:s)已经有数据“2021-06-11 17:23:36”
我尝试了以下代码,但它只显示正确的 $post->ID,它不显示 $submitdate。
控制台没有错误。
请告诉我如何回显该字段的值?
我试过的查询:
$args = array(
'post_type' => 'project',
'posts_per_page' => -1,
'author' => get_current_user_id(),
'name' => get_the_title()
);
$query = new WP_Query($args);
if ($query->have_posts()) {
global $post;
while ($query->have_posts()) {
$query->the_post();
$submitdate = get_post_meta($post->ID, 'submitdate', true);
echo $post->ID;
echo $submitdate;
}
}
我也试过,它显示当前日期和时间,而不是字段中的值:
$submitdate = get_field("submitdate", $post->ID);
谢谢。
【问题讨论】:
标签: php mysql wordpress advanced-custom-fields