Help - how do I legally nest PHP?

by 1 replies
2
Can anyone help - I've literally been googling for about 5 hours and can't figure this out.

I want to take the output of the first php statement (which outputs an attachment id for an image) and use it to replace the XX in the second statement (if I put the attachment id in there it displays the image).

But I don't know how to legally nest php

Can anyone save my sanity??

<?php
global $wp_query;
$postid = $wp_query->post->ID;
echo get_post_meta($postid, 'hh-product-image', true);
?>

<?php echo wp_get_attachment_image( XX ); ?>
#programming #legally #nest #php
  • <?php
    global $wp_query;
    $postid = $wp_query->post->ID;
    $output = get_post_meta($postid, 'hh-product-image', true);
    ?>

    <?php echo wp_get_attachment_image( $output ); ?>

    or

    <?php
    global $wp_query;
    $postid = $wp_query->post->ID;

    ?>

    <?php echo wp_get_attachment_image( get_post_meta($postid, 'hh-product-image', true) ); ?>

    Did I understand you correctly?

Next Topics on Trending Feed

  • 2

    Can anyone help - I've literally been googling for about 5 hours and can't figure this out. I want to take the output of the first php statement (which outputs an attachment id for an image) and use it to replace the XX in the second statement (if I put the attachment id in there it displays the image).