• solutho

    (@solutho)


    Hello, I’ve spent 1 hour trying to figure this out..

    I have the following code inside the loop for the articles:

    <?php if ($attachments) { foreach ($attachments as $attachment) { ?>
    				<img src="<?php echo wp_get_attachment_url($attachment->ID); ?>" />
    				<?php }} ?>

    What does attached really mean? It’s not inserting it into the post, right?
    Thank you

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter solutho

    (@solutho)

    Anyone?

    jettj09

    (@jettj09)

    Are you calling the get_posts function before running through the for loop? For example, I use this code in my website to get attachments:

    $args = array( 'post_type' => 'attachment', 'numberposts' => -1, 'post_status' => null, 'post_parent' => $page_id );
    		$attachments = get_posts($args);

    What that is saying is that I want to get all of the attachments for the post/page with the id $page_id.

    After you do that you should easily be able to get the attachment URL.

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘How does wp_get_attachment_url work?’ is closed to new replies.