高级自定义字段插件-无法从POST_OBJECT获取URL

时间:2012-01-17 作者:rpeg

我不确定我在这里做错了什么。我有一个名为“grid\\u缩略图”的字段和一个“related\\u projects”post\\u对象。我能够显示相关帖子的标题。我只是不知道如何获取相关帖子的图片URL。建议?

<?php foreach(get_field(\'related_projects\') as $post_object): ?>

<li>
<img src="<?php echo get_field(\'grid_thumbnail\'); ?>"><br />
<a href="<?php echo get_permalink($post_object->ID); ?>"><?php echo get_the_title($post_object->ID) ?></a>
</li>
编辑打印返回:

stdClass Object ( [ID] => 100 
[post_author] => 1 
[post_date] => 2012-01-12 05:11:25 
[post_date_gmt] => 2012-01-12 05:11:25 
[post_content] => Nulla facilisi. Pellentesque non tincidunt est. Nulla porta bibendum auctor. Proin feugiat eros bibendum lacus viverra fringilla ac id felis. Praesent a commodo leo. Phasellus et odio eget justo venenatis interdum at ut nulla. Praesent lacinia nulla eu libero tempus pulvinar. Sed elementum, nulla vitae imperdiet ornare, elit lorem vestibulum erat, ac aliquet purus lacus pharetra risus. Mauris facilisis volutpat odio a ultrices. Etiam nisl urna, mattis sed ultricies sit amet, euismod sit amet eros. Nam tempus erat ut ligula elementum cursus faucibus elit accumsan. Fusce rhoncus, nunc nec vestibulum facilisis, nibh leo vestibulum metus, vitae malesuada leo dui eu erat. Proin scelerisque, mi viverra dignissim porta, lectus justo pellentesque metus, at consequat ligula nulla eu ante. Fusce fringilla pretium venenatis. Quisque quis arcu porta dolor condimentum viverra at id augue. Donec pharetra venenatis felis. 
[post_title] => Rada 
[post_excerpt] => 
[post_status] => publish 
[comment_status] => open 
[ping_status] => open 
[post_password] => 
[post_name] => rada-2 
[to_ping] => 
[pinged] => 
[post_modified] => 2012-01-16 23:01:37 
[post_modified_gmt] => 2012-01-16 23:01:37 
[post_content_filtered] => 
[post_parent] => 0 
[guid] => http://estevancarlos.kodingen.com/ecv7/?post_type=projects&p=100 
[menu_order] => 0 
[post_type] => projects 
[post_mime_type] => 
[comment_count] => 0 
[ancestors] => Array ( ) [filter] => raw )

2 个回复
最合适的回答,由SO网友:mor7ifer 整理而成

上还有第二个参数get_field() 如果您没有使用,请尝试这一行:

<img src="<?php echo get_field( \'grid_thumbnail\', $post_object->ID ); ?>"><br />

文档:get_field()

SO网友:Quasimo

使用addslashes 在PHP中。

如中所述this page (中文)这将有效:

$main_car_pic = addslashes(get_field(\'car_photo\'));
$reg_ext = "#.jpg#i";
$thumb_ext = "-150x150.jpg";
$car_thumb = preg_replace($reg_ext, $thumb_ext, $main_car_pic);

echo $car_thumb
或者简单地说:

<?php echo addslashes(get_field(\'field_name\')); ?>

结束

相关推荐