• Hi,
    I’m looping through image attachment to display images and thumbnails for a portfolio page using WordPress (of course). I’m trying to pull the data from the new “Alternate Text” field available for WP 2.9 but I’ve been unable to find where this data is stored.

    I’m able to get data from the other fields using the below code but where is ‘Alternate Text’ field info?

    Here is what is entered in the WP back-end for this image:
    Title: Personal1L
    Alternate text: Personal 1 Alt Text
    Caption: Personal 1 Caption
    Description: Personal 1 Description
    Link URL: (its blank)

    Here is the output of the below code for this image:
    ID: 53
    post_author: 1
    post_date: 2010-01-27 06:33:52
    post_date_gmt: 2010-01-27 06:33:52
    post_content: Personal 1 Description
    post_title: Personal1L
    post_excerpt: Personal 1 Caption
    post_status: inherit
    comment_status: closed
    ping_status: open
    post_password:
    post_name: personal1l
    to_ping:
    pinged:
    post_modified: 2010-01-27 06:33:52
    post_modified_gmt: 2010-01-27 06:33:52
    post_content_filtered:
    post_parent: 30
    guid: http://localhost/sitename/wp-content/uploads/Personal1L.jpg
    menu_order: 4
    post_type: attachment
    post_mime_type: image/jpeg
    comment_count: 0
    filter: raw

    And here is relevant code:

    <!--This is happenening inside the Loop-->
    <?php
    $args = array(
      'post_type' => 'attachment',
      'numberposts' => -1,
      'post_status' => null,
      'post_parent' => $post->ID,
      'post_mime_type' => 'image',
      'orderby' => 'menu_order',
      'order' => 'ASC',
      );
    ?>
    <?php $attachments = get_posts($args); ?>
    
    <?php if ($attachments) { ?>
    	<?php foreach ($attachments as $attachment) { ?>
    		<!--Loop through attachements (images) -->	
    
    		<?php foreach ($attachment as $key => $value) {?>
    		  <!--Loop through each attachement (image) and display all associated key : value pairs-->	
    
              <p><?php echo $key; ?>: <?php echo $value ?></p>
    
    		<?php }; // nested foreach ?>
    
    		<!--End loop through attachements-->
    	<?php } //foreach ?>
    <?php } //if ?>

    Thanks!
    John

Viewing 5 replies - 1 through 5 (of 5 total)
Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Get ‘Alternate Text’ from attachments’ is closed to new replies.