WordPress.org

Ready to get started?Download WordPress

Forums

Random Attachment - Limiting to specific category (2 posts)

  1. shaneholden
    Member
    Posted 4 years ago #

    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.

    Thanks!

  2. shaneholden
    Member
    Posted 4 years ago #

    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!

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.