Add link based on membership level and post date
-
Hi there,
I’m working on a widget for a website that needs to only place the permalink to a post if A: the user is a given level and B: the post is X number of days old.
I’ve already done something similar to filter out posts from the main blogroll based on date+user role, but I can’t seem to get it to work in this instance.
Here is the code that I have been using. In two of the if/else statements I have two different versions I’ve been trying, one of which is commented out.
//Stuff to make sure widget obeys s2member $gmt_timestamp = get_post_time('U', true); //if ( current_user_can('access_s2member_level1') && strtotime($post->post_date) > strtotime('-1 day') ) : if ( current_user_can('access_s2member_level1') && $gmt_timestamp > strtotime('-2 days') ) : $anchor_open = '<a href="' . get_the_permalink() . '">'; $anchor_close = '</a> '; elseif ( current_user_is('s2member_level2') || current_user_can('update_core') ) : $anchor_open = '<a href="' . get_the_permalink() . '">'; $anchor_close = '</a> '; //elseif ( current_user_can('access_s2member_level0') && strtotime($post->post_date) > strtotime('-2 days') ) : elseif ( current_user_can('access_s2member_level0') && $gmt_timestamp > strtotime('-1 day') ) : $anchor_open = '<a href="' . get_the_permalink() . '">'; $anchor_close = '</a> '; else : $anchor_open = ""; $anchor_close = ""; endif;
NOTE: I’m not trying to drip feed content based on the user’s registration date. I need to allow/disallow access based on the date a given post was published.
If you could let me know what I’m doing wrong, or if there is an easier way to do this I would much appreciate it!
- The topic ‘Add link based on membership level and post date’ is closed to new replies.