Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'm not sure what I'm doing wrong here. I have a field called "grid_thumbnail" and a "related_projects" post_object. I am able to display the title of the related post. I just don't know how to get the Image URL of that related post. Suggestions?

<?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>

Edit

print_r returns:

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 )
share|improve this question
    
what does a print_r( $post_object ) give you? I have a feeling that $post_object is not a post object... –  m0r7if3r Jan 17 '12 at 1:26
    
You can take a look here: estevancarlos.kodingen.com/ecv7/… –  rpeg Jan 17 '12 at 2:08
    
I'm inclined to believe, based on that, that the issue is in your get_field(), either that or you're having a variable name conflict with $post_object. get_field() is not a wordpress core function, where is that function coming from? –  m0r7if3r Jan 17 '12 at 3:42
    
I am using the Advanced Custom Fields plugin. It comes from that. –  rpeg Jan 18 '12 at 17:45
    
Why not use $post_object->title? Are you just looking for the filters? Also, is the permalink working and just the title's broken? –  m0r7if3r Jan 18 '12 at 19:28

2 Answers 2

up vote 2 down vote accepted

There is a second parameter on get_field() which you are not using, try this line instead:

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

Docs: get_field()

share|improve this answer

Use addslashes in PHP.

As described in this page (in chinese), this would work:

$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

Or simply like this:

<?php echo addslashes(get_field('field_name')); ?>
share|improve this answer
    
Hi, Quasimo, welcome to WordPress StackExchange! . . Note that only a link to an external site is not considered a good Answer. . . . Please take a moment to read this Stack FAQ to better understand its mechanics. –  brasofilo Jul 31 '12 at 15:09

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.