2016-07-29 2 views
0

私たちにはACF Pro for WPがあり、選択された場所を示すACFが作成されています。アドバンストカスタムフィールドが表示されない

私たちは、この取得されて出力しようとして:

お知らせ: /ホーム/ cwplantactiveint/public_htmlの/ WP-コンテンツ/テーマ/ cwplant /ループ・ジョブで非オブジェクトのプロパティを取得しようとします。ライン66本

<?php $location = get_field('job_location'); echo $location->post_title; ?> 

は今奇妙な、それは別のカスタムフィールドを出力する

上のPHP createdto出力された日付:

<?php if(get_field('closing_date')) { ?> 
<?php the_field('closing_date'); ?> 
<?php } else { ?> 
Ongoing 
<?php } ?> 

全体のコードブロックは次のようになります。

<?php while (have_posts()) : the_post(); ?> 

<?php /* Check closing date is not past. */ 


$today = strtotime("now"); 
$closedate = strtotime(get_field('closing_date')); 


if ($today < $closedate || !get_field('closing_date')) { 

?> 

<div class="singlepost infobox info-job content cfix"> 
     <h2><a href="<?php the_permalink(); ?>" title="<?php printf(esc_attr__('Permalink to %s', 'twentyten'), the_title_attribute('echo=0')); ?>"><?php the_title(); ?></a></h2> 
     <p><span class="red first">Location:</span> <?php $location = get_field('job_location'); echo $location->post_title; ?> 


     <span class="red">Closing Date:</span> 

     <?php if(get_field('closing_date')) { ?> 
    <?php the_field('closing_date'); ?> 
    <?php } else { ?> 
    Ongoing 
    <?php } ?> 

      </p> 

    <?php if (is_archive() || is_search() || is_home()) : // Only display excerpts for archives and search. ?> 
      <?php the_excerpt(); ?> 
      <a class="button" href="<?php the_permalink(); ?>">View Details</a> 
    <?php else : ?> 
      <?php the_content(__('Continue reading &rarr;', 'twentyten')); ?> 
    <?php endif; ?> 



</div> 

<?php $jobstrue = 'true'; ?> 

    <?php } else { ?> 
    <?php $jobsfalse = 'true'; ?> 
    <?php } ?> 

<?php endwhile; // End the loop. Whew. ?> 
+0

注: '$ closedate =のstrtotime(get_field( 'closing_date'));' - 'get_field ($ location){do_something} 'のようにポストする必要があります。 –

+0

これは、' true 'または 'false'を返すでしょう。' the_field(' closing_date ') 'アーカイブテンプレートまたは通常のテンプレートですか? – staypuftman

+0

@staypuftmanこれは標準の新しいページテンプレートです。 – PhpDude

答えて

1

私はあなたの問題はあなたがそうあなたのクエリが返すwp_reset_postdata()$postオブジェクトをリセットしていないということだと思います最後のものは$post(あなたの場合はcreatedto)です。

私はWPで任意のオブジェクトを扱うとき、私はいつもそれを設定し、このようにそれをリセットします。

<?php 
// YOUR CUSTOM FIELD 
// 0- Reset post object from last query (this should really be part of your last query) 
wp_reset_postdata(); 

// 1- Put custom field into post object and check for content 
$post_object = get_field('location'); 

// 2- Check to make sure object exists and setup $post (must use $post variable name) 
if ($post_object) { 
    $post = $post_object; 
    setup_postdata($post); 

    // 3- Do some magic 
    echo get_field('closing_date'); 

    // 4- reset postdata so other parts of the page can use it 
    wp_reset_postdata(); 
} 
?> 
関連する問題