我想通過查詢所有帖子來獲得一個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 –