[英]How to get the meta value of the ACF field (wordpress)?
I need to get the meta value of the ACF field.我需要获取 ACF 字段的元值。
ACF field called 'submitdate' (format => Date Time picker: Ymd H:i:s) already has data '2021-06-11 17:23:36'名为“submitdate”的 ACF 字段(格式 => 日期时间选择器:Ymd H:i:s)已经有数据“2021-06-11 17:23:36”
I tried the following code, but it only shows correct $post->ID, it doesn't show $submitdate.我尝试了以下代码,但它只显示正确的 $post->ID,它不显示 $submitdate。
No error in console.控制台没有错误。
Would you please let me know how to echo the value of the field?请让我知道如何回显该字段的值?
Query I tried:我试过的查询:
$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;
}
}
I also tried, it shows current date and time, not the value in the field:我也试过,它显示当前日期和时间,而不是字段中的值:
$submitdate = get_field("submitdate", $post->ID);
Thank you.谢谢你。
/* I had same issue before few days and resolved with below function */
/* please try this line of code */
$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_field('submitdate', $post->ID ); // if changed field name then update key in this query
echo $post->ID;
echo $submitdate;
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.