Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'm using this code to list the image attachments of a post:

      <select name="chb_homes_for_sale_specifics_floor_plan" style="width:100%;">
        <option value="">Select</option>
        <?php
        $args = array(
            'numberposts'     => -1,
            'orderby'         => 'menu_order',
            'order'           => 'ASC',
            'post_type'       => 'attachment',
            'post_parent'     => $post->ID,
            'post_mime_type' => 'image'
        );
        $image = get_posts($args);
        if($image) {
            foreach($image as $key => $data) : ?>

                <option value="<?php echo $data->ID; ?>"><?php echo $data->post_title; ?></option>

            <?php endforeach;
        }
        ?>
      </select>

But what I'm showing currently is the attachment post_title but I want to show the file name instead. I could maybe use get attachment URL then parse the URL to get the file name but was wondering if there is a ready made way in WordPress to get the file name.

share|improve this question

1 Answer 1

up vote 13 down vote accepted

I would strongly advise against using $post->guid - WordPress now generates them in the form;

http:/example.com/?attachment_id=ID

Use the same method that many of the attachment-related functions use;

$filename = basename ( get_attached_file( $data->ID ) );
share|improve this answer
3  
And here is the link to the discussion –  kaiser Jun 15 '11 at 15:07
    
link is dead :( –  simonthesorcerer Nov 7 at 17:22

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.