• jaybuddy

    (@jaybuddy)


    So I am working on some custom code that uses the query from the wp-postviews plugin SQL statement to pull the posts with the most views. Everything works fine except the “the_excerpt();” call which seems to pull the excerpt of a random post… not the excerpt of the post pulled from the sql statement. Does anyone see any problems with my code as to why this would be happening?

    Here is the code.

    <?php $results = $wpdb->get_results("SELECT DISTINCT $wpdb->posts.*, (meta_value+0) AS views FROM $wpdb->posts LEFT JOIN $wpdb->postmeta ON $wpdb->postmeta.post_id = $wpdb->posts.ID WHERE post_date < '".current_time('mysql')."' AND post_status = 'publish' AND meta_key = 'views' AND post_password = '' ORDER  BY views DESC LIMIT 4"); ?>
    
    <?php foreach($results as $post) {
    ?>
    
    <div class="popborder">
    <img src="<?php echo bloginfo('template_url'); ?>/thumb.php?src=<?php echo get_post_meta($post->ID, "image", $single = true); ?>&amp;h=57&amp;w=100&amp;zc=1&amp;q=95" class="th" align="left"/>
    <h3><a title="Permanent Link to <?php the_title(); ?>" href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></h3>
    		<span class="popular"><?php the_excerpt(); ?></span>
    
    </div>
    <?php } ?>

The topic ‘help with custom code. the_exerpt() not working’ is closed to new replies.