2014-04-08 53 views
0

我想以下,從http://www.advancedcustomfields.com/resources/field-types/post-object/,但它只能輸出空的div:循環自定義後的對象與高級自定義字段

<?php $post_objects = get_field('project_experts'); 

if($post_objects): ?> 
    <div class="row expert"> 
    <?php foreach($post_objects as $post): ?> 
    <?php setup_postdata($post); ?> 
     <div class="mt-one-half"> 
      <h3><a href="<?php echo get_permalink(); ?>"><?php echo get_the_title(); ?></a></h3> 
      <?php the_excerpt(); ?> 
     </div> 
    <?php endforeach; ?> 
    <?php wp_reset_postdata(); ?> 
    </div> 
<?php endif; ?> 

但是我知道的信息是那裏當我嘗試<?php print_r(get_field('project_experts') ); ?>我得到:

Array ([0] => Array ([project_expert] => WP_Post Object ([ID] => 763 [post_author] => 1 [post_date] => 2014-03-27 17:57:29 [post_date_gmt] => 2014-03-27 17:57:29 [post_content] => 

等等等等

用於從陣列斂值任何指針?

謝謝!

回答

1

你很近。你只需要在get_field返回的數組中更深入一級。

<?php foreach($post_objects as $array): ?> 
    <?php foreach($array as $obj): ?> 

<?php setup_postdata($obj); ?> 
    <div class="mt-one-half"> 
     <h3><a href="<?php echo get_permalink(); ?>"><?php echo get_the_title(); ?></a></h3> 
     <?php the_excerpt(); ?> 
    </div> 
    <?php endforeach; ?> 
<?php wp_reset_postdata(); ?> 
<?php endforeach; ?> 
//etc... as before 
+0

非常感謝!我認爲專家會看到它的蝙蝠。 :) –

+0

沒問題。我點擊以查看您的網站順便說一句。華麗的設計作品。祝你好運和智慧。 – larsAnders

+0

再次感謝larsAnders! –

相關問題