Skip Navigation

[Resolved] Rotate posts monthly

This support ticket is created 4 years, 4 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

This topic contains 1 reply, has 2 voices.

Last updated by Christian Cox 4 years, 4 months ago.

Assisted by: Christian Cox.

Author
Posts
#1705193
department.PNG

Hi - I'm not sure if this is possible. But I was wondering how / if I could pull a post onto my homepage and have it update monthly.

I have a custom post type called Department. I have created several department posts which each give information about a different department in my company. What I am trying to do is feature a different (either random or we could do it alphabetically) department on the homepage each month. I.e it would be automatic I wouldn't have to update it manually, it would just cycle through the available posts showing a new one each month.

Thanks!

#1705561
Screen Shot 2020-07-13 at 11.35.22 AM.png

Hi, there's nothing exactly like this filter built into the system, but you could set up your own custom automated system with two custom date fields added to the Department post type. One would be the start date and the other would be the end date. In each post, you'll set the start and end dates to be the first of the month and the last of the month, respectively, for the month where you want the post to be "featured". For example, if you want to display a post in the month of March next year, you'll set the start date field to be March 1, 2021 and you'll set the end date field to be March 31, 2021.

Then in a View of Department posts, you will add two Query Filters: one for the start date and another for the end date. The start date should be a "number", with a value greater than or equal to TODAY() and the end date should be a "number", with a value less than FUTURE_MONTH(1). See the screenshot here for an example where the field "book date" represents the start date and field "book date 2" represents the end date.

While this is probably the easiest method to set up, it does require some maintenance because the year of the start and end dates is considered by the filter. At some time in the future after a post is featured, someone must update the start and end date fields of that post to select the first and last of the month for the following year. There is no simple workaround here, unfortunately.

Another option that requires custom code is to create a single number custom field on the Departments post type. Store a number that corresponds to the featured month for each post (1 for January through 12 for December). Create a custom shortcode that returns the numeric index of the current month (1 for January through 12 for December). Create a View of Departments posts with a Query filter based on this custom field, set to use a shortcode attribute like currentmonthnumber. Then place your custom shortcode inside that View attribute, so the filter responds to the current month. I did a quick search and found this very similar WordPress shortcode. It returns the Year using date format 'Y'. You want the month using date format 'n', so you could make that change in the code and rename the shortcode to be something more appropriate:
https://css-tricks.com/snippets/wordpress/year-shortcode/
Register the shortcode name in Toolset > Settings > Front-end Content > 3rd party shortcode attributes, and you can use it in the View shortcode attribute for your Query Filter. So this is a more difficult solution to implement, but on the other hand it does not require yearly maintenance.