Suggested Feature: Time limit posts
-
I’ve made a small change to your code to allow “fresh” posts only to be displayed using the short code e.g.
[display-posts id=26697 expire=2014-10-01]I enclose the patch for your consideration:
diff U3 F:/Documents/hockey/WP/diaplay-posts-shortcode/display-posts-shortcode.vanilla v2.4/display-posts-shortcode.php F:/Documents/hockey/WP/diaplay-posts-shortcode/display-posts-shortcode v2.4/display-posts-shortcode.php --- F:/Documents/hockey/WP/diaplay-posts-shortcode/display-posts-shortcode.vanilla v2.4/display-posts-shortcode.php Wed May 07 15:34:54 2014 +++ F:/Documents/hockey/WP/diaplay-posts-shortcode/display-posts-shortcode v2.4/display-posts-shortcode.php Fri Jul 18 23:17:10 2014 @@ -80,6 +80,7 @@ 'wrapper' => 'ul', 'wrapper_class' => 'display-posts-listing', 'wrapper_id' => false, + 'expire' => '' ), $atts, 'display-posts' ); // End early if shortcode should be turned off @@ -120,7 +121,7 @@ $wrapper_id = sanitize_html_class( $atts['wrapper_id'] ); if( !empty( $wrapper_id ) ) $wrapper_id = ' id="' . $wrapper_id . '"'; - + $expire = sanitize_text_field( $atts['expire'] ); // Set up initial query for post $args = array( @@ -248,7 +249,7 @@ $listing = new WP_Query( apply_filters( 'display_posts_shortcode_args', $args, $original_atts ) ); - if ( ! $listing->have_posts() ) + if ( ! $listing->have_posts() || (($expire !== '') && (strtotime($expire) < strtotime(date("Y-m-d")))) ) return apply_filters( 'display_posts_shortcode_no_results', wpautop( $no_posts_message ) ); $inner = '';
The topic ‘Suggested Feature: Time limit posts’ is closed to new replies.