I have a page where I'm pulling in content from another post, outside of the loop.
I've been successfull at getting the content of the specified post, but I cannot get the image from a custom field (advanced custom image field).
This is working to get the content from the post who's ID is 299:
$my_id = 299; $post_id_299 = get_post($my_id); $content_299 = $post_id_299->post_content; $content_299 = apply_filters('the_content', $content_299); $content_299 = str_replace(']]>', ']]>', $content_299); $content_299_chars = 238; $modcontent_299 = substr($content_299, 0, $content_299_chars);
<p><?php echo $modcontent_299; ?></p>
This is what I'm after to get the image from the post who's ID is 299 (if it exists):
$attachment_id = get_field('image', 299); $size = 'full'; $image = wp_get_attachment_image_src( $attachment_id, $size ); if( get_field('image') ): echo '<img src="' . $image . '" alt="' . the_title() .'" width="238" height="158" />'; endif;
I'm sure I need to change some of these variables to get the image field from the specific post id, similar to how it's done to get the content, but I'm confused at this point as to how to do that for a custom field...