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

  • andrains



    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


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



    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:

    				        global $post;
    				        $args = array( 
    				        	'numberposts' => $dis_posts, 
    				        	'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'comments' ),
    				        	'date_query' => 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 class='topBullTitle'>
    					        	<a href="<?php the_permalink(); ?>"> <?php the_title(); ?></a>
    					        	<span class='topBullCount'><?php echo get_post_meta($post->ID, '_reaction_buttons_0', 'meta_value_num'); ?>  </span>
    				        <?php endforeach; ?>
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Widget: Limit posts to past week’ is closed to new replies.