• Resolved farzadbayan

    (@farzadbayan)


    Using the thumbs_rating_top shortcode, the posts with zero votes are not in the list. There are just posts with >0 votes.

    Besides, I wrote a function to order my posts by the number of votes. Again, posts with 0 votes are not queried:

    add_action('pre_get_posts', 'orderby_hot_posts');
    
    function orderby_hot_posts($query){
    	if($query->is_home && empty($query->query_vars['suppress_filters'])){
    		update_post_meta($post_ID, "_thumbs_rating_up", 1);
    		$query->set( 'meta_key' , _thumbs_rating_up);
    		$query->set( 'orderby' , 'meta_value_num');
    	}
    }

    How to show all posts (including those not-yet-voted)?

    https://wordpress.org/plugins/thumbs-rating/

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Ricard Torres

    (@quicoto)

    Good question, I don’t know 🙂

    Hi!

    My solution has been to put two loops on the page… :O
    The second loop excludes all post with _thumbs_rating_up meta_key

    First, show the post with votes:

    <!-- Posts només amb vots -->
    
     <?php
    $args = array (
    	    	'post_type' 			 => 'post',
    			'post_status'            => 'publish',
    			'cat'                    => '2',
    			'pagination'             => false,
    			'posts_per_page'         => '100',
    			'cache_results'          => true,
    			'meta_key'	=> '_thumbs_rating_up', // or '_thumbs_rating_down'
    			'orderby'	=> 'meta_value_num',
    		);
    $postslist = get_posts( $args );
    foreach ( $postslist as $post ) :
      setup_postdata( $post ); ?> 
    
      <div class="post-2016">
    
    <li><a>"><?php the_title(); ?></a></li>
        <?php
    if ( has_post_thumbnail() ) {
    	$large_image_url = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'full' );
    	echo '<a href="' . $large_image_url[0] . '" title="' . the_title_attribute( 'echo=0' ) . '">';
    	echo get_the_post_thumbnail( $post->ID, 'large' );
    	echo '</a>';
    }
    ?>
    
    <?=function_exists('thumbs_rating_getlink') ? thumbs_rating_getlink() : ''?>
    </div>
    
    <?php endforeach;
    wp_reset_postdata(); ?>
    
    <!-- Posts només amb vots END -->

    And then… show all the post excluding _thumbs_rating_up meta_key:

    <!-- Posts sense vots -->
    
    <?php
    $excludeposts = $wpdb->get_col( "SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_thumbs_rating_up' AND meta_value != '' ORDER BY post_id DESC LIMIT 0, 100" );
    
    $main_query = new WP_Query( array(
        'post__not_in' => $excludeposts,
        'paged' => $paged,
    	'cat' => '2',
    	'posts_per_page' => '100',
        )
    );
    while ($main_query->have_posts()) : 
    
        $main_query->the_post();?>
    
    	<div <?php post_class(); ?> id="post">
    
    <div class="thumb"><a>"><?php the_post_thumbnail('thumbnail' , 'alt="' . $post->post_title . '"' , $post->ID, array()); ?></a></div>
    <p class="date"><?php the_time('d/m/Y') ?></p>
    <h1><a>"><?php the_title(); ?></a></h1>
    
    <?=function_exists('thumbs_rating_getlink') ? thumbs_rating_getlink() : ''?>
    
    </div>
    <?php endwhile;
    ?>
    <!-- Posts sense vots END -->

    Perhaps not very elegant, but it works!

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Posts with zero votes are not queried’ is closed to new replies.