Title: How correctly to use WordPress Time parameters
Last modified: August 21, 2016

---

# How correctly to use WordPress Time parameters

 *  [sem8seo](https://wordpress.org/support/users/sem8seo/)
 * (@sem8seo)
 * [12 years, 10 months ago](https://wordpress.org/support/topic/fi/)
 * I started to work on one website after another developer and there is problem
   with his “widget” in function.php which is basically showing 3 random posts from
   category. There is some Switch statement which is regulating to show from category
   news 3 random post not older then 1 month and for other categories 3 month. I
   don’t understand what he did there with [‘interval’] but when I use wordpress
   time parameters still I don’t have results. I am not experienced with wordpress
   time parameters, so I would need help about it.
 *     ```
       function getSomePost($category,$postsPerPage=3) {
               global $post;
   
               $args = array(
                   'category_name'=>$category,
                   'posts_per_page'=>$postsPerPage,
                   'post_type'=>'post',
                   'post_status'=>'publish',
                   'post__not_in'=>array($post->ID),
                   'orderby'=>'rand',
               );
   
               switch ($category)
               {
                   case 'news':
                       $args['interval'] = '1 MONTH';
                       break;
                   case 'analysis':
                       $args['interval'] = '3 MONTH';
                       break;
                   case 'reports':
                       $args['interval'] = '3 MONTH';
                       break;
               }
   
               $query = new WP_Query($args);
   
               if ( $query->have_posts() ) {
                      while ( $query->have_posts() ) {
                      $query->the_post();
                      $postThumbClass = 'no-thumb';
                      ?>
                          <div <?php post_class(array('wp-post-entry', 'sidebar-post' )); ?>>
                           <?php if(has_post_thumbnail ()):?>
                               <?php $postThumbClass = '' ?>
                               <div class="wp-post-thumbnail">
                                   <a href="<?php the_permalink() ?>">
                                       <?php the_post_thumbnail(array(70,70)); ?>
                                   </a>
                               </div>
                            <?php endif; ?>
   
                           <div class="wp-post-full-content <?php echo $postThumbClass ?> ">
                               <h3 class="wp-post-title"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
       <!--
                               <div class="post-content">
                                   <?php the_excerpt() ?>
                               </div>
       //-->
                           </div>
                       </div>
                      }
               }
   
           }
       ```
   
 * I was trying to replace inside switch
 *     ```
       case 'news':
                       $args['interval'] = '1 MONTH';
                       break;
       ```
   
 * with
 *     ```
       case 'news':
           // Create a new filtering function that will add our where clause to the query
           function filter_where( $where = '' ) {
               // posts in the last 30 days
               $where .= " AND post_date > '" . date('Y-m-d', strtotime('-30 days')) . "'";
               return $where;
           }
   
           add_filter( 'posts_where', 'filter_where' );
           $query = new WP_Query( $args );
           remove_filter( 'posts_where', 'filter_where' );
           break;
       ```
   
 * and
 *     ```
       case 'analysis':
                           $args['interval'] = '3 MONTH';
                           break;
       ```
   
 * with
 *     ```
       case 'analysis':
       // Create a new filtering function that will add our where clause to the query
       function filter_where( $where = '' ) {
           // posts in the last 30 days
           $where .= " AND post_date > '" . date('Y-m-d', strtotime('-90 days')) . "'";
           return $where;
       }
   
       add_filter( 'posts_where', 'filter_where' );
       $query = new WP_Query( $args );
       remove_filter( 'posts_where', 'filter_where' );
       break;
       ```
   
 * but it is not working I tried also to use if ($category == ‘news’) but it breaks
   the site

The topic ‘How correctly to use WordPress Time parameters’ is closed to new replies.

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 0 replies
 * 1 participant
 * Last reply from: [sem8seo](https://wordpress.org/support/users/sem8seo/)
 * Last activity: [12 years, 10 months ago](https://wordpress.org/support/topic/fi/)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
