• Resolved rhyseden

    (@rhyseden)


    Hy.

    I’ve got some problem here when trying to display posts ordered by votes.
    Note : I added a column named ‘votes’ into wp_posts.

    here’s the code

    $popular_posts = new WP_Query('orderby=votes&order=DESC');
    	<?php if ($popular_posts->have_posts()) : ?>
    		<?php while ($popular_posts->have_posts()) : $popular_posts->the_post(); ?>
    		<div class="post" id="post-<?php the_ID(); ?>">
    
    			<div class="entry">
    				<?php the_excerpt(); ?>
    			</div>
    		</div>
    
    		<?php endwhile; ?>
    
    	<?php else : ?>
    
    	<?php endif; ?>

    does anyone has a suggestion? pls tell me.
    thx.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Don’t think you can sort on anything but a predefined list of fields when using query_posts. See if this works for you;

    <?php
    $post_ids = $wpdb->get_col("SELECT ID FROM $wpdb->posts WHERE post_status = 'publish' AND post_type = 'post' ORDER BY votes");
    foreach($post_ids as $post_id) {
    $posts=get_posts('p='.$post_id);
    if ($posts) {
    foreach($posts as $post) {
    setup_postdata($post);
    ?>
    <a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a>
    
    <?php }
    }
    }
    ?>

    Thread Starter rhyseden

    (@rhyseden)

    Wow great! it works well ??

    thanks MichaelH.

    Thanks MichaelH,

    but have can I add pagination to display only certain number of posts per page?

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘custom query for popular post’ is closed to new replies.