我想通过查询所有帖子来获得一个acf创建的自定义字段。显示登录用户的自定义字段
我试过如下:
<?php
if (is_user_logged_in()):
global $current_user;
$current_user = wp_get_current_user();
$author_query = array('post_status' => array('draft'),
'author' => $current_user->ID,
'meta_query' => array(
array(
'key' => 'wpgamail_options',
'key' => 'ganalytics_settings',
),
),);
$author_posts = new WP_Query($author_query);
while($author_posts->have_posts()) : $author_posts->the_post();
?>
<tr>
<td>
<?php the_title(); ?>
</td>
<td>
<?php $post_date = get_the_date(); echo $post_date; ?>
</td>
<td>
<?php $field = get_field('wpgamail_options', $author_posts->the_post()->ID, true); echo $field['nextfetchtime']; ?> //here I get the error
</td>
</tr>
<?php
endwhile;
else :
echo "You are not logged in. Please log in!";
endif;
?>
我收到以下错误信息:
注意:试图让非对象的属性在未知行0通话 堆栈:3.9772 231600 1. {main}()/home/ubuntu/workspace/index.php:0 3.9774 232048 2. require('/ home/ubuntu/workspace/wp-blog-header.php')/ home/ubuntu/workspace/index.php:17 4.6285 8745184 3. require_once('/ home/ubuntu/workspace/wp-includes/template-loader.php') /home/ubuntu/workspace/wp-blog-header.php:19 4.6328 8788784 4. include('/ home/ubuntu/workspace/wp-content/themes/twentysixteen/page-create-report.php') /home/ubuntu/workspace/wp-includes/template-loader.php:75 1469999466
任何建议,我所使用[get_field()][1]
功能做错了什么?
我很感谢你的回复!
这是不正确的。 'the_ID()'显示ID,而在这里它需要被返回。在这种情况下使用正确的函数是'get_the_ID()' –
@IgorYavych很好的评论谢谢!但只是一个评论,你不需要添加像你解决NP难题的答案:D –