Support » Fixing WordPress » 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.


Viewing 1 replies (of 1 total)
  • Just wanted to do a quick check and see if anyone knew how to do this? I’ve not been able to come up w/ it, and may just abandon the idea if I can’t get it to work like this. Thanks!

Viewing 1 replies (of 1 total)
  • The topic ‘Random Attachment – Limiting to specific category’ is closed to new replies.