Support » Plugin: Reaction Buttons » Widget: Limit posts to past week

  • andrains

    (@andrains)


    Hi,

    Can you tell me what code changes would be required to limit the widget list of posts to those created in the past 7 days? Or month, or year, for that matter.

    It would be helpful as we want the posts in the widget to stay relatively fresh.

    Thank you!

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Jakob Lenfers

    (@jakob42)

    I simply don’t have time to work on this, I would accept patches though.

    andrains

    (@andrains)

    I achieved it by creating a separate widget plugin using wp_query instead of wpdb.
    Seemed easier than editing the existing plugin and breaking updatability in the future.

    The gist of it is:

     <ul>
    				    <?php
    				        global $post;
    				        $args = array( 
    				        	'numberposts' => $dis_posts, 
    				        	'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'comments' ),
    				        	'date_query' => array(
    						        array(
    						            'after' => '4 week ago'
    									)
    												 ),
    							'meta_key' => '_reaction_buttons_0',
    							'orderby' => 'meta_value_num',
    							'order' => 'DESC'
    							
    				        	);
    				      
    				        $myposts = get_posts( $args );
    				        foreach( $myposts as $post ) : setup_postdata($post); ?>
    				        <li class='topBull'>
    					        <div class='topBullImage'>
    						        		
    								<a href="<?php the_permalink(); ?>"> <?php the_post_thumbnail(array(100,100));?></a>
    					        </div>
    					        <div class='topBullTitle'>
    					        	<a href="<?php the_permalink(); ?>"> <?php the_title(); ?></a>
    					        	<br>
    					        	<span class='topBullCount'><?php echo get_post_meta($post->ID, '_reaction_buttons_0', 'meta_value_num'); ?>  </span>
    					        </div>
    					 
    				        </li>
    				        <?php endforeach; ?>
    				</ul>
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Widget: Limit posts to past week’ is closed to new replies.