Solved

Get posts for last month, build links for previous months

Posted on 2013-10-31
1
267 Views
Last Modified: 2013-11-14
I am building a feed page for what is basically an online newsletter.  What I'd like is to show the posts in the feed by month, displaying only the current month's info.

I am having no problem building the feed to display the posts, but can't find where to set the date information for the layout.

Here's my current loop.

<?php
					$today = getdate();
					$args = array( 'numberposts' =>15 , 'category_name' => 'news' , 'post_date' = '$today');
					$lastposts = get_posts( $args );
					foreach($lastposts as $post) : setup_postdata($post); ?>
						<?php the_title(); ?>
            	
            		<?php endforeach; ?>

Open in new window


I am trying to use $getdate(); to find the current month but didn't see any options in the WP Codex to add the results of that to my array.

Additionally, I'd like to add links on the bottom of the page where the user can select a month, and it would then rebuild the feed changing the variable to the selected month.

Thanks!
0
Comment
Question by:axessJosh
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 17

Accepted Solution

by:
jrm213jrm213 earned 500 total points
ID: 39616631
<?php
                                        $year = date("Y"); //4-digit year
                                        $month = date("n"); //month without leading zeros
					$args = array( 'numberposts' =>15 , 'category_name' => 'news' , 'year'=$year,'month'=$month);
					$lastposts = get_posts( $args );
					foreach($lastposts as $post) : setup_postdata($post); ?>
						<?php the_title(); ?>
            	
            		<?php endforeach; ?>
                                  

Open in new window


That should work for you.

You can use any parameter of wp_query with the get_posts function.
0

Featured Post

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I want to start by talking about the use of plug-ins for WordPress. I started a web-site for a company I was working for a few years ago; I had extremely basic knowledge of HTML. I am a Graphic Designer by trade so I invited the opportunity as a cha…
Transferring a wordpress site from a host or local dev server to another host can be a pain. So I've included my steps on how I have accomplished this task. Steps include an assumption that you have Cpanel access or Ftp access.. If you do not hav…
The purpose of this video is to demonstrate how to make a WordPress Site faster and smaller in size by cleaning up the database. This will be demonstrated using a Windows 8 PC. Plugin WP Optimize will be used. Go to your WordPress login page. T…
This video teaches users how to migrate an existing Wordpress website to a new domain.

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question