How to Display Posts for specific time period

Add Tool

Display Posts for specific time period


Hello guys hwo are you? Today I will share a wordpress snippet to display published posts for specific time period. I think you know about job portal websites. Generally Job portal websites publish there new jobs for 30 days or another time period. After expiration the time of job news the job deleted from the job list. Want to Display Posts for a specific time period Here is an easy way to create posts that will only be displayed for the duration of a specific time period. You can set the time using wordpress custom field or wordpress advanced custom fields plugin.

Display Posts for specific time period custom loop

Replace your current loop with the following wordpress code snippet: (You should create a backup of your current loop for future use).

<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
	$expirationtime = get_post_custom_values('expiration');
	if (is_array($expirationtime)) {
		$expirestring = implode($expirationtime);
	}
	$secondsbetween = strtotime($expirestring)-time();
	if ($secondsbetween > 0) { ?>

		<h1><?php the_title(); ?></h1>
		<?php the_excerpt(); ?>

<?php } endwhile; endif; ?>

And then add a custom field named 'expiration' to any post that needs an medication expiration date . For the value of the expiration key, specify the date/time in the following format: mm/dd/yyyy 00:00:00. Each post that contains such a custom field will expire after the specified date and time and will no longer appear in the loop. Now you know how easy to Display Posts for specific time period or Display Published Posts for Certain Time Period.


Tags: wordpress custom loop, wordpress loop, Posts for a specific time period, medication expiration date
Payza

About Masum Billah

Display Posts for specific time period 1stWebSuite website seo tool is a free website ranking tool site provides a lot of on page and off page seo useful tools for you. On this site, we have a large number of website ranking tools


SIGN UP TO GET UPDATE TO YOUR INBOX




Discuss about: How to Display Posts for specific time period


adf.ly