title: query random image from Wordpress Media Library
body: <p>If i am using the the plugin "Enhanced Media Library" and i want to display a random image, can i somehow use a WP_query to do this?</p>
  
  <p>With the plugin activated this is how my media library looks like: 
  <a href="https://i.stack.imgur.com/w1sNb.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/w1sNb.png" alt="enter image description here"></a></p>
  
  <p>I have created a category called: "imgfront", and i then want to display a random image from this category on a specific page. I tried the following query:</p>
  
  <pre><code>           $image = new WP_Query( 
              array(
                  'post_type' =&gt; 'attachment', 
                  'media_category' =&gt; 'imgfront',
                  'posts_per_page' =&gt; '1', 
                  'orderby' =&gt; 'rand',   
                  )
              );  
  
          if( $image-&gt;have_posts() ){
              $image_attributes = wp_get_attachment_image_src( $image-&gt;posts[0], 'full' );
              ?&gt;&lt;img src="&lt;?php echo $image_attributes[0]; ?&gt;"&gt; &lt;?php
          }
  </code></pre>
  
  <p>The query does noot seem to return any images though. </p>