Need advice to connect 31 custom fields with a date variable
-
Hello, first time I’ve posted, I usually try to solve problems myself but I have hit a brickwall with my amateur PHP knowledge.
I hope someone who knows their stuff can advise me on a better way:
I have developed a website for a freind whos family owns a restaurant https://www.grado.cz.
Each month there is a list of all the specials for that month (for up to 31 days) which is shown in the specials menu. “https://www.grado.cz/specials_menu/prosinec-2011/”. I made this using a custom field panel with 31 custom fields for each day. However things get more complex when she then told me she’d like the special of the day to appear each day on the frontpage. Not being very good at PHP I constructed a simple variable that captures the day of the month then used a SWITCH with 31 CASES to show todays special menu item:
switch ($gradospecial) { case 1: $test_special = get_post_meta($post->ID, 'dayone', true); echo $test_special; break; case 2:
It all works but the problem is that to do this each custom field has to have its own unique ID name. Which means a SWITCH with 31 items!!!
I’m wondering if anyone can advise me on a better way to do this? As this seems bloated.
So I guess I’m asking:
Is there a way to add 31 custom fields all with the same custom field ID to a new ARRAY which would automatically number them 01 > 31 so that the ‘Variabe=date’ variable could check to see which one it should use and then display the right one depending on the day of the month?
I’ve tried to read up on arrays but I think I’m missing some fundamental concept somewhere….any suggestions appreciated…
- The topic ‘Need advice to connect 31 custom fields with a date variable’ is closed to new replies.