Build Your Own Business Website header image

Community Library Website – Part 46, Display Posts from the Last 60 Days

Difficulty Level -

Whoops, you've found some premium content!

Watch the opening clip of this video to preview it,
the full video is available to paid members.

This is the 44th in a series of live lessons on using WordPress and Thesis as a Content Management System (CMS). In this lesson we modify the custom loop for our custom catalog page. This custom loop will display recent posts organized by custom taxonomy. We create a “date filter” that will allow us to display all posts from the last 60 days.

Community Library Website – Case Study Part 1 – Site Organization
Community Library Website – Case Study Part 2 – Create Custom Post Types
Community Library Website – Case Study Part 3 – Custom Post Type Configuration
Community Library Website – Case Study Part 4 – Custom Taxonomy Decisions – Theory
Community Library Website – Case Study Part 5 – Custom Taxonomy Decisions – Practical Application
Community Library Website – Case Study Part 6 – Incorporating Existing Data Into the Project
Community Library Website – Case Study Part 7 – Creating Hierarchical Custom Taxonomies
Community Library Website – Case Study Part 8 – Creating Non-Hierarchical Custom Taxonomies
Community Library Website – Case Study Part 9 – Creating Custom Post Meta
Community Library Website Case Study – Part 10a – Restore the Database Using BackupBuddy
Community Library Website Case Study- Part 10 – Creating Custom Post Meta – Continued
Community Library Website – Part 11 – Importing Existing Data to the Website
Community Library Website – Part 12 – Prepare Existing Data for import by the CSV Importer plugin
Community Library Website – Part 13 – Import Existing Data Using the CSV Importer Plugin
Community Library Website – Case Study Part 14 – Date in Permalink Configuration
Community Library Website – Part 15 – Importing Images
Community Library Website – Part 16b – Final Data Import
Community Library Website – Part 17 – Add Thesis Post Meta to Custom Post Type
Community Library Website – Part 18 – Add WordPress 3.0 Menus
Community Library Website – Part 19 – Add Post Meta and Taxonomy Information to the Post Display
Community Library – Part 20 – Add topics and audience to book display
Community Library – Part 21 – Display the Rest of the Post Meta in the Post
Community Library Website – Part 22, Create the Permalink Structure
Community Library – Part 23 – Remove Custom Post Meta from Post Display
Community Library Website – Part 24, Add Taxonomy and Post Meta Data to the Teaser
Community Library Website – Part 25, Add Taxonomy Data to the Teaser
Community Library Website – Part 26, Adjust the Teaser Styling Using Design Options
Community Library Website – Part 27, Styling the Teaser Using CSS
Community Library Website – Part 28 – Fine Tune the Teaser Display
Community Library Website – Part 29, Designing a Custom Catalog Page
Community Library Website – Part 30, Using a Query String in a URL
Community Library Website – Part 31, Adding Custom WordPress Menus
Community Library Website – Part 32, Add Custom Menus to the Catalog Page
Community Library Website – Part 33, Add Another Custom Menu to the Catalog Page
Community Library Website – Part 34, Troubleshooting Custom Menus
Community Library Website – Part 35, Add Styling to WordPress Menus
Community Library Website – Part 36, Add HTML Markup to WordPress Menus
Community Library Website – Part 37, Add WordPress Menus to Archive Pages
Community Library Website – Part 38, Add and Style a List of Tags
Community Library Website – Part 39, Add a Search Box to the Sidebar
Community Library Website – Part 40, Add Links to the Sidebar
Community Library Website – Part 41, Add Taxonomy Drill Down Browsing
Community Library Website – Part 42, Custom Loop to Display Custom Post Types
Community Library Website – Part 43, Simple Custom Query
Community Library Website – Part 44, Custom Taxonomy Query
Community Library Website – Part 45, Add Thesis HTML Structure to Teasers
Community Library Website – Part 46, Display Posts from the Last 60 Days
Community Library Website – Part 47, Custom Loop If Have Posts
Community Library Case Study – Part 48, Increase the Number of Posts that Display on the Custom Catalog
Community Library Website – Part 49 – Naming Conflicts in Custom Taxonomies
Community Library Website – Part 50 – Find and Replace Semi-colons in the Database
Community Library Website – Part 51 – Modify Taxonomy Names Directly in the Database
Community Library Website – Part 52 – Sort Posts by Meta Value
Community Library Website – Part 53 – Show the Term Label Only when a Term Exists
Community Library Website – Part 54 – Sort Archive Posts by Meta Value
Community Library Website – Part 55 – Add Sort Order to Custom Taxonomy

Video Transcript

That brings us back to add the date filter to this loop. Now unfortunately, WordPress does not actually have a date filter. So if we type wp query… or WordPress doesn’t have what you’d like it to have for date.

If we go to the wp query and we look at its potential arguments and we look at let’s see, not order by but time parameters you know, you can say show dates of this year or show dates of this month or show dates of this week or this day or this hour and so on and so forth. But what you can’t do… and you can say from March 1st to March 15th but what you can’t do is say for the last 30 days or the last 60 days or the last 90 days. And of course, we want the last 60 days.

And so, what we’re going to do is we are going to… rather than using a query variable which is what we’ve been doing, we are going to use a filter. And that filter, what that filter is going to do is it’s going to change the MySQL statement and it’s going to add this value which essentially says go back 30 days. And you could actually change everything you know, everything in the query this way if you wanted to but it’s the hard way to do it. But nevertheless, it’s the only way to do it in WordPress for you know, something a date that’s not defined, a date that’s essentially calculated from today’s date or any other given period of time.

So we’re going to say the last… we’re going to take this filter and we’re going to put it in our function. And actually, we’re not putting it in our function, it is its own separate function. And right now, if we uploaded this, this would apply to every single instance of the query which we don’t want. We don’t want it to apply to every instance of the query which means that we need to include this add filter in a conditional statement that says you know, only do it in this case. Well you know, it seems to me like the best way to do that is just to come up here in our query and do it.

And so, we have my query equals new wp query. So I’m suggesting that we just put that filter here. And now this filter is only going to be added when this query is being called. Otherwise, if this function isn’t being called, this filter isn’t being called. So this filter’s going to be called every time the query is being called but that’s only going to get called when this page is being called or this function’s being called.

So we’re going to add the filter where… we’re going to add this filter post where with the name filter where and that’s what’s happening here. So we’re doing it to 30 days. Now unfortunately… well, I’m just going to show you. We’ll go ahead and save this and we’ll upload it… it’s not what I wanted. We’ll upload it and we’ll take a look at it. What’s going to happen is you won’t see any posts. And the reason you won’t see any posts is because I don’t have any posts. I don’t have any catalog items that are less than 30 days old, 3 days or less old. And so now, it’s not showing anything.

So what I have to do is I have to change that for my data set, I can’t use 3 days or 60 days. I actually have to use 150 day because that’s how old my data set is. So in this area, I put 150 and I save the document and I upload the document and we check it.

Now every… now what happens is I don’t have any books that meet the 150 day reference. So we’d just write audiobooks. I’ve got Bible and Reference that do, I’ve got 3 books there so it puts it under Bible and Reference. I’ve got 3 books under… or 2 books under Biographies, none under children’s ebooks but I’ve got one under DVDs. A couple of them under fiction or more than a couple under fiction… several under fiction, none under holidays, none under junior fiction, none under junior nonfiction. Now, we’re back to Missions and then nonfiction.

0 Comments… add one

Save $200 on Membership Now!

Start learning today for as little as
$0.82 PER DAY!
THIS IS A LIMITED TIME OFFER!
Subscription Options
0 comments… add one

Leave a Comment