Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7893971
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T07:16:24+00:00 2026-06-03T07:16:24+00:00

Having a little trouble in getting image attachment urls in wordpress. This is my

  • 0

Having a little trouble in getting image attachment urls in wordpress. This is my code so far:

<?php // find images attached to this post / page.
            global $post;
            $thumb_ID = get_post_thumbnail_id( $post->ID );
            $args = array(
                'post_type' => 'attachment',
                'post_mime_type' => 'image',
                'numberposts' => -1,
                'orderby' => 'menu_order',
                'order' => 'ASC',
                'exclude' => $thumb_ID,
                'post_parent' => $post->ID
            );
            $images = get_posts($args);
            ?>

            <?php // Loop through the images and show them

            if($images)
            {
            foreach($images as $image)  
            {

            echo  wp_get_attachment_image_url($image->ID, $size='attached-image');

            }
            }

?>

Which returns nothing. If I swap out wp_get_attachment_image_url($image->ID, $size='attached-image'); for wp_get_attachment_image($image->ID, $size='attached-image'); this works fine, but brings in the image rather than just the url.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T07:16:25+00:00Added an answer on June 3, 2026 at 7:16 am

    The following code will loop through all image attachments and output the src url. Note that there are two methods shown, depending on your need.

    <?php
    
        global $post;
        $args = array( 'post_type' => 'attachment', 'numberposts' => -1, 'post_mime_type' => 'image', 'post_status' => null, 'post_parent' => $post->ID ); 
        $attachments = get_posts($args);
        if ($attachments) {
                foreach ( $attachments as $attachment ) {
                        // Method #1: Allows you to define the image size
                        $src = wp_get_attachment_image_src( $attachment->ID, "attached-image");
                        if ($src) {echo $src[0];}
                        // Method #2: Would always return the "attached-image" size
                        echo $attachment->guid;
                }
        }
    
    ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having a little trouble getting this query to work: $userId = mysql_real_escape_string( $_SESSION['user_id']
I am having a little trouble getting this to work. I have several anchor
I'm just getting started with using php DOMDocument and am having a little trouble.
I'm just getting started with using php DOMDocument and am having a little trouble.
I'm having a little trouble of getting an image/drawable or a bitmap from a
I hit this linker error and am having a little trouble getting past it.
I'm new to Watir and I've having a little trouble getting logged in in
I'm having little trouble creating a script working with URLs. I'm using urllib.urlopen() to
I'm having a little trouble as I decide how to structure my projects. This
I'm having trouble getting a custom config section to work. It's some code I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.