I have a project where I need to display an alternating food menu each week.

  • i.e. menu1 on week1, menu2 on week2 then back to week1 etc.
  • I’ve created custom post types for each menu (menu1 & menu2).

Ideally, if the user wanted to see what the food menu was going to be next week, they would click on a calendar day a week from today & the food menu would display week2’s food menu.

I could deal with changing the food menu per week by having different custom pages to pull the different custom post types, but this does not solve the above requirement of what was on next week.

2 Answers
2

You can use PHP’s date functionality:

// set (or retrieve) the number of menus
$num_menus = 2;
// calculate the current/next menu according to the current/next week (number)
$current_menu = date('W') % $num_menus;
$next_menu = (date('W') + 1) % $num_menus;

All you have to do then, is to map the numbers to the according menus (i.e., custom post types).

Leave a Reply

Your email address will not be published. Required fields are marked *