Title: Randomly show post attachment
Last modified: August 21, 2016

---

# Randomly show post attachment

 *  [sayagdan](https://wordpress.org/support/users/sayagdan/)
 * (@sayagdan)
 * [12 years, 4 months ago](https://wordpress.org/support/topic/randomly-show-post-attachment/)
 * Hi
    The best way to explain is to show my code :
 * <?php
    if (have_posts()) : $c = 0; while ( have_posts() ) : the_post(); $c++;
   if ( $c == 1) { $style = “current first”; } elseif ( $c == count( $posts ) ) {
   $style = “last”; } /* elseif ( $c == 2 ) { $style = “”; }*/
 * else $style =’dispa’;
 * ?><?php
    $images =& get_children( array ( ‘post_parent’ => $post->ID, ‘post_type’
   => ‘attachment’
 * ));
    foreach ( $images as $attachment_id => $attachment ) {
 * ?><div <?php post_class($style) ?>id =”post_<?php echo $post->ID;?>”><?php echo
   wp_get_attachment_image( $attachment_id, ‘large’ ); }
 * ?><div <?php post_class(‘mezzanine ‘ . $style) ?>><?php $description = $attachment-
   >post_content;
    echo $description; ?></div></div><?php endwhile; wp_reset_postdata();
   else : echo wpautop( ‘Sorry, no posts were found’ ); endif; ?>
 * The result of this is to show the attachement image that is directly attached
   to the current post.
    I want to show the posts / posts attachments in random 
   order though i noticed that adding the ‘orderby’ => ‘rand’ function is not helping.
   Does anyone could help me with this? Thank you in advance
 * if you want to see the actual result you can go on [http://blog.dansayag.com](http://blog.dansayag.com)
 * The blog I need help with is blog.dansayag.com.

The topic ‘Randomly show post attachment’ is closed to new replies.

## Tags

 * [attachment](https://wordpress.org/support/topic-tag/attachment/)
 * [post](https://wordpress.org/support/topic-tag/post/)
 * [query](https://wordpress.org/support/topic-tag/query/)
 * [routine](https://wordpress.org/support/topic-tag/routine/)
 * [show](https://wordpress.org/support/topic-tag/show/)

 * 0 replies
 * 1 participant
 * Last reply from: [sayagdan](https://wordpress.org/support/users/sayagdan/)
 * Last activity: [12 years, 4 months ago](https://wordpress.org/support/topic/randomly-show-post-attachment/)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
