Community Forums › Forums › Archived Forums › Design Tips and Tricks › Limit Posts Displayed To Specified Time Frame
- This topic has 7 replies, 2 voices, and was last updated 9 years, 8 months ago by JamesDunn.
-
AuthorPosts
-
August 11, 2014 at 8:20 pm #118317JamesDunnMember
Goodday All.
I'm working with a Radio Station website and we have several customized blog pages that I created using query_args and setting the specific category number for each page. However, on some of the pages, I'd like to only show posts that were made in a specific time frame. An example would be the News Page - I'd probably like to only show the news articles that were posted in the past five days or so. On the School Closings Page (during severe weather), I'd like to only show postings that have been made since midnight (or some other specified time) so that each day it's a fresh list of closings. There are a couple of other category pages that would have their own time frames.
Can I put anything in the Custom Fields area (like I did with query_args) to make that happen or will I have to actually code something into the functions.php file? I've seen some code to put there that should work, but with needing different time frames for different categories, I was hoping that it could be customized in the custom fields.
Thanks in advance for any help.
JDD
http://wmsl.fm/alerts/August 12, 2014 at 1:01 am #118340Brad DaltonParticipantYes but you would need to be very specific.
Here's one solution you can modify http://wpsites.net/wordpress-tips/show-posts-between-specific-date-period/
What are you doing with custom fields because you shouldn't need to modify that code at all.
Check out all the parameters WP_Query
If you can, you might find it easier to use pre_get_posts for this as long as it allows you to use the parameters you need. Not sure what code you already have.
August 12, 2014 at 1:09 am #118341Brad DaltonParticipantAnother option is to use the date/time functions http://php.net/manual/en/function.date.php
Here's an example of using them to display different content in widgets each day.
August 12, 2014 at 5:30 am #118369JamesDunnMemberHey Brad.
I'm using the Custom Fields as outlined in this StudioPress article: http://my.studiopress.com/tutorials/category-blog-page/ - to create a category blog page (actually several). Since I learned this little trick, I have used it lots. But, the radio station guy wants to "expire" posts from the list after a certain period of time - time that varies based on the type of post.
I've seen this article: https://trovepromo-tf.trove-stg.com/0m1-sd/stackoverflow.com/questions/15349692/filter-posts-by-a-range-of-dates-in-the-genesis-framework-on-wordpress - but I'm not 100% certain it will work with the custom fields method. It looks like it works if you create a custom loop for each of the categories. Am I correct?
I was actually trying to NOT create those custom loops if at all possible because using the custom fields is so simple to set up that I can show someone in the radio station how to do it and even they can set them up for other pages.
Thanks in advance.
JDD
August 12, 2014 at 7:22 am #118383Brad DaltonParticipantMight be easier to use a plugin in that case https://wordpress.org/plugins/post-expirator/
August 12, 2014 at 9:16 pm #118492JamesDunnMemberYep, I use Post Expirator on some sites, but it doesn't work on this site because there are some items that are posted using another plugin (Postie) and it doesn't trigger whatever posting manual does so that Post Expirator will work properly.
Yeah, I'm a heap of trouble aren't I? 😉
JDD
August 12, 2014 at 9:46 pm #118499Brad DaltonParticipantI think there's only 2 solutions.
Use a plugin or custom code.
The problem i find with plugins are that they are hard to modify but on the other hand you don't need coding skills.
Custom code is flexible but you also need to understand how it works.
What you could do is add custom code for posts in existing categories which will work automatically for all or specific categories.
August 12, 2014 at 10:58 pm #118506JamesDunnMemberI'm convinced that it can be done that way Brad - and I can do it. I'm just lazy enough to try to find an easier way if there is one. LOL
Thanks for all your comments here.
JDD
-
AuthorPosts
- The forum ‘Design Tips and Tricks’ is closed to new topics and replies.