title: Show Wordpress posts for limited time (depending on the value of a custom field)
body: <p>I want to show Wordpress posts for a limited time (1 or 2 weeks) after their publication. For the duration I've created a custom field (<code>advertorial_duur</code>) which has either value <code>1</code> (1 week) or <code>2</code> (2 weeks).</p>
  
  <p>It displays some posts already, but not according to the duration I've set in the posts. I can't figure it out exactly but I think it now displays posts for just 1 week regardless of the custom field value.</p>
  
  <p>So far I've produced this code:</p>
  
  <pre><code>&lt;ul class="advertorials"&gt;
      &lt;?php
      $advertorials = new WP_Query( 'cat=18' ); 
  
      while ($advertorials-&gt;have_posts()) :
  
          $advertorials-&gt;the_post();        
  
          if ( (current_time(timestamp) - get_the_time('U') - (get_settings('gmt_offset') * 3600) ) &lt; ((int)get_post_custom_values( 'advertorial_duur' ))*(7*60*60*24))
          {
      ?&gt;
  
      &lt;li&gt;&lt;a href="&lt;?php the_permalink(); ?&gt;" title="Lees meer over: &lt;?php the_title(); ?&gt;"&gt;
          &lt;div class="thumb"&gt;&lt;?php the_post_thumbnail('thumbnail') ?&gt;&lt;/div&gt;
          &lt;p class="title"&gt;&lt;?php the_title(); ?&gt;&lt;/p&gt;
          &lt;div class="clr"&gt;&lt;/div&gt;&lt;/a&gt;
      &lt;/li&gt;
  
      &lt;?php } ?&gt;
  
      &lt;?php endwhile; ?&gt;
      &lt;?php wp_reset_query(); ?&gt;
  &lt;/ul&gt;    
  </code></pre>