Forums

Anyone see what's wrong with this query? (2 posts)

  1. imaginethepoet
    Member
    Posted 2 years ago #

    I've been working for about 2 hours on this now. I'm trying to pull out 7 random posts and 1 custom fields (in addition to title, link to the post, ) - to display an image strip of 7 images. I am also using "get the image". I have it working but, the query seems to be ignoring the LIMIT and ORDER BY RAND.

    <?php $new_query = new WP_Query("SELECT * FROM $wpdb->posts ORDER BY RAND() LIMIT 7", ARRAY_A); ?>
    
    <?php while ($new_query->have_posts()) : $new_query->the_post(); ?>
    
    <?php get_the_image( array( 'custom_key' => array( 'thumb_gallery' ), 'default_size' => 'medium', 'width' => '100', 'height' => '100','image_scan' => true,'image_class' => 'tm_image' ) ); ?>
    
    <?php endwhile; ?>

    Anyone have any ideas I'm so close now but just a little bit further to go.

  2. CharlesClarkson
    Member
    Posted 2 years ago #

    Do you have a "global $wpdb;" before this code and can you tell us what you are getting instead of the 7 random posts?

    HTH,

Topic Closed

This topic has been closed to new replies.

About this Topic