Random Attachment – Limiting to specific category
This is the code that Matt recently posted for a random attachment thumbnail. I’m wanting to limit it to a specific category, but for some reason I can’t figure it out.
<?php $hilite = $wpdb->get_var( "SELECT ID FROM $wpdb->posts WHERE post_type = 'attachment' AND ORDER BY RAND() LIMIT 1" ); echo '<a href="' . get_permalink($hilite) . '">' . wp_get_attachment_image( $hilite, 'thumbnail' ) . '</a>'; ?>
Hopefully it is a quick and easy something that I’m missing.
- The topic ‘Random Attachment – Limiting to specific category’ is closed to new replies.