2014-04-08 56 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! –

相关问题