This is post two for me here, so my apologies if I leave something out! I’m also pretty weak at wordpress coding, but I’m learning!
I’m using a portfolio template to organizes pages of educational content. Each page has 5 posts, one for each weekday (Mon-Fri). I’ll have different groups accessing different pages each week, but most of the pages will be “old”. So, when visiting them now, you see all 5 days at once.
I want them to only see the previous and current days posts. So, visiting on Monday, you see only Monday’s post, even though Monday-Friday is published. Visiting on Wednesday you see Mon-Wed.
All of the pages are the same, there will only ever be 5 posts. This method doesn’t have much flexibility, but that’s ok. I’ll likely include a meta checkbox to “enable/disable” this functionality, but won’t need to use that much.
Here’s a link to the current template-portfolio.php: https://gist.github.com/4671326
And here’s the one I tried to modify: https://gist.github.com/4661867
Here’s the relevant bit of code:
$days = array(
'monday' => 1,
'tuesday' => 2,
'wednesday' => 3,
'thursday' => 4,
'friday' => 5,
);
$args = array(
'post_type' => 'portfolio',
'orderby' => 'menu_order',
'order' => 'ASC',
'meta_value' => esc_attr( get_post_meta( $post->ID, 'portsort', true ) ),
'posts_per_page' => $days[date( 'l', current_time('timestamp') )],
);
My additions aren’t working. Here’s the logic I was trying to put in there:
Show #number# of posts depending on what day it is. So, if the date returns Thursday, then just show 4 posts.
To me, that seems like it would be easy to do… but it’s not working right for some reason.
SO… my questions:
- Is this the appropriate coding logic for this to work smoothly?
- What have I done incorrectly in the code itself?
Thanks for the help!
Older question but might simply be a an issue of case sensitivity: