• Resolved foots

    (@foots)


    I’m trying to show attached files in the post on the front end. How can I pull the post ID please?

    I’m using this code:

    <?php // get post attachments
    $post_attachments = get_posts( array (
    ‘post_type’ => ‘attachment’,
    ‘post_parent’ => $post->ID,

    ));
    ?>

      <?php foreach ( $post_attachments as $post_attachment ) {
      echo ‘

    • ‘ . wp_get_attachment_link( $post_attachment->ID, ”, false, false ) . ‘
    • ‘;
      } ?>

    The code returns all the attachments, not just the ones attached to the post. If I set the post ID I get the correct attachment. What should the post_parent be set to?

    Many Thanks.

Viewing 1 replies (of 1 total)
  • Thread Starter foots

    (@foots)

    I was able to show the attachements by changing

    ‘post_parent’ => $post->ID, to ‘post_parent’ => $thispost->ID,

    All the best.

Viewing 1 replies (of 1 total)
  • The topic ‘Show Attachements’ is closed to new replies.