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!
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.