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?
With the plugin activated this is how my media library looks like:
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:
$image = new WP_Query( array( 'media_category' => 'imgfront' ) );
if( $image->have_posts() ){
$image_attributes = wp_get_attachment_image_src( $image->posts[0], 'full' );
?><img src="<?php echo $image_attributes[0]; ?>"> <?php
}
Aucun commentaire:
Enregistrer un commentaire