In this article I will show you how to retrieve the wordpress posts within specific time frame.
WordPress is providing as full proof wordpress api so we can achieve the this using wordpress api only.
You can use the query_posts() function for fetching the wordpress posts. Open your index.php from your wordpress template folder. Before loop just use the following code for in index.php file.
$current_date = getdate(); query_posts(monthnum=' .$current_date["mon"] );
You can pass the multiple parameters to query_posts function as per your requirement.
- hour= – hour (from 0 to 23)
- minute= – minute (from 0 to 60)
- second= – second (0 to 60)
- day= – day of the month (from 1 to 31)
- monthnum= – month number (from 1 to 12)
- year= – 4 digit year (e.g. 2009)
- w= – week of the year (from 0 to 53)
Now I will show the another example. which will show only current date post on home page.
$current_date = getdate();
query_posts('year=' .$current_date["year"] .'&monthnum=' .$current_date["mon"] .'&day=' .$current_date["mday"] );
Another good example for fetching the 30 days latest post from wordpress
<?php
//based on Austin Matzko's code from wp-hackers email list
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_posts($query_string);
?>
Incoming search terms:
- wordpress get posts by month
- current month wordpress homepage
- wordpress show all post of the month
- wordpress posts by month
- wordpress monthnum
- wordpress get post from month
- wordpress get post by month
- wordpress api get all posts
- wordpress all posts by month on home page
- show month of posts in wordpress
- query post multiple monthnum
- posts by month wordpress
- list all posts wordpress 3 2
- how to display one month post page wordpress
- homepage display by month
- display only this months posts in wordpress
- display all post by month wordpress
- current_time last post dans wordpress
- wordpress show recent posts for the month






great infromation
Hi,
Firstly, many thanks for this little snippet, it has been a great help.
However, I am running into a problem when using the following:
The above works, except it displays the first, most recent post twice. Am I doing anything wrong?
Many thanks!