2016-07-31 2 views
0

모든 게시물을 쿼리하여 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 231,600을 1. {main}() /home/ubuntu/workspace/index.php : 3.9774 232048 2./home/우분투/workspace/wp-blog-header.php가 필요합니다. index.php : 17 4.6285 8745184 3. require_once ('/ home/우분투/workspace/wp-includes/template-loader.php') /home/ubuntu/workspace/wp-blog-header.php:19 4.6328 8788784 4. 은 ('/ home/우분투/wp-content/themes/twentysixteen/page-create-report.php')를 포함합니다. 나는 [get_field()][1] 기능을 사용하여 잘못하고있는 무슨 /home/ubuntu/workspace/wp-includes/template-loader.php:75 1469999466

어떤 제안?

답장을 보내 주셔서 감사합니다.

답변

1

$author_posts->the_post()->ID을 사용하고 있으며 get_the_ID() (ID가 표시된 the_ID()이 아님)을 사용해야합니다.
고정 코드.

<?php 
$field = get_field('wpgamail_options', get_the_ID(), true); 
echo $field['nextfetchtime']; ?> 

또한 $current_user = wp_get_current_user();을 수행 할 필요가 없습니다. $current_user global에는 현재 사용자 개체가 이미 있습니다.

1

$author_posts->the_post()은 루프의 게시물 색인을 반복하는 데 사용되지만 현재 게시물에 액세스하는 데 사용할 수 없습니다. 대신 get_the_ID을 사용할 수 있습니다.

<?php $field = get_field('wpgamail_options', get_the_ID(), true); 
     echo $field['nextfetchtime']; ?> 

이 정보가 도움이되기를 바랍니다.

+0

올바르지 않습니다. 'the_ID()'는 ID를 표시하고 여기서 반환해야합니다. 이 경우에 사용할 올바른 함수는'get_the_ID()'입니다. –

+0

@IgorYavych nice remark thank you! 단 한 번의 주석은 NP 어려운 문제를 해결 한 것처럼 답을 추가 할 필요가 없습니다. D –

관련 문제