Skip to content

Instantly share code, notes, and snippets.

@jpcontrerasv
Created July 30, 2014 14:53
Show Gist options
  • Save jpcontrerasv/94bb85f3ef39a1af8dce to your computer and use it in GitHub Desktop.
Save jpcontrerasv/94bb85f3ef39a1af8dce to your computer and use it in GitHub Desktop.
Loop Ultimos 7 días
<?php
function filter_where($where = '') {
//only show posts published within the last 30 days
$where .= " AND post_date > '" . date('Y-m-d', strtotime('-7 days')) . "'";
return $where;
}
add_filter('posts_where', 'filter_where');
// Query posts
query_posts( 'cat=3&posts_per_page=1&orderby=rand' );
// The Loop
if (have_posts()) : while ( have_posts() ) : the_post(); ?>
<?php the_content(); ?>
<?php
endwhile; endif;
//remove the filter
remove_filter('posts_where', 'filter_where');
// Reset Query
wp_reset_query();
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment