Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/269.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/63.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何获取ACF字段(wordpress)的元值?_Php_Mysql_Wordpress_Advanced Custom Fields - Fatal编程技术网

Php 如何获取ACF字段(wordpress)的元值?

Php 如何获取ACF字段(wordpress)的元值?,php,mysql,wordpress,advanced-custom-fields,Php,Mysql,Wordpress,Advanced Custom Fields,我需要得到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, 'aut

我需要得到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);

谢谢。

嗨:谢谢你的帮助。我试过了,但它显示的是当前日期和时间,而不是字段中的值。你能告诉我怎么解决这个问题吗?谢谢。可能是可变冲突。您可以更改变量名并尝试是否确定?您的密钥和post id是否正确?您好,我在ACF中更改了字段名唯一名称,但它仍然显示当前时间…您好wpdevloper___j:非常感谢您的支持帮助。我喜欢吃杂碎。我为名为“submitdate”的ACF字段设置了日期时间选择器:Y-m-d H:I:s。我使用$value\u date=current\u datetime;保存帖子时自动保存值。我所发现的是,这个领域的时间发生了变化。它保持当前时间。。。你的代码运行得很好,只是字段有问题,我想。。。
/* 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; 
     }
   }