Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions classes/widget.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ public function update( $new_instance, $old_instance ) {
$instance['offset'] = intval( $new_instance['offset'] );
$instance['order'] = stripslashes( $new_instance['order'] );
$instance['orderby'] = stripslashes( $new_instance['orderby'] );
$instance['date_filter'] = stripslashes( $new_instance['date_filter'] );
$instance['date_filter_adj'] = intval( $new_instance['date_filter_adj'] );
$instance['post_type'] = $types;
$instance['post_status'] = stripslashes( $new_instance['post_status'] );
$instance['cat'] = $new_instance['cat'];
Expand Down
21 changes: 21 additions & 0 deletions includes/form.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,27 @@
</select>
</p>

<p>
<label for="<?php echo $this->get_field_id( 'date_filter' ); ?>">
<?php _e( 'Date Filter', 'recent-posts-widget-extended' ); ?>
</label>
<select class="widefat" id="<?php echo $this->get_field_id( 'date_filter' ); ?>" name="<?php echo $this->get_field_name( 'date_filter' ); ?>" style="width:100%;">
<option value="all" <?php selected( $instance['date_filter'], 'all' ); ?>><?php _e( 'All Dates', 'rpwe' ) ?></option>
<option value="after" <?php selected( $instance['date_filter'], 'after' ); ?>><?php _e( 'Future Dates', 'rpwe' ) ?></option>
<option value="before" <?php selected( $instance['date_filter'], 'before' ); ?>><?php _e( 'Past Dates', 'rpwe' ) ?></option>
</select>
</p>

<p>
<label for="<?php echo $this->get_field_id( 'date_filter_adj' ); ?>">
<?php _e( 'Date Filter Adjustment', 'recent-posts-widget-extended' ); ?>
</label>
<input class="widefat" id="<?php echo $this->get_field_id( 'date_filter_adj' ); ?>" name="<?php echo $this->get_field_name( 'date_filter_adj' ); ?>" type="number" step="1" value="<?php echo (int)( $instance['date_filter_adj'] ); ?>" />
<small><?php _e( 'Adjustment in days. Negative values allowed. Only used if Date Filter set to future or past dates.', 'rpwe' );?></small>
</p>



<div class="rpwe-multiple-check-form">
<label>
<?php _e( 'Limit to Category', 'recent-posts-widget-extended' ); ?>
Expand Down
4 changes: 4 additions & 0 deletions includes/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,10 @@ function rpwe_get_posts( $args = array() ) {
$query['tag__in'] = $args['tag'];
}

if( $args['date_filter'] != 'all' ) {
$query['date_query'] = array('column' => 'post_date', $args['date_filter'] => $args['date_filter_adj'] . ' days' );
}

/**
* Taxonomy query.
* Prop Miniloop plugin by Kailey Lampert.
Expand Down