You’re using get_the_date() wrong. That function gets the date of the post in a given format, and the 2nd argument is the Post ID for the post to get the date for. Not a time.
The simplest way to do this would be to just use timestamps. So you can just get the post date timestamp and add 3 days using the DAY_IN_SECONDS constant that WordPress provides:
if (
! is_user_logged_in()
&& in_category( array( 'test2', 'test1' ) )
&& current_time( 'U' ) <= get_the_date( 'U' ) + ( 3 * DAY_IN_SECONDS )
) {
echo 'Sorry';
} else {
the_content();
}
}
The key bit being:
current_time( 'U' ) <= get_the_date( 'U' ) + ( 3 * DAY_IN_SECONDS )
This should avoid issues with differences in timezones between current_time() and strtotime().
PS: I also changed your multiple in_category() calls into a single call with an array.
Related Posts:
- Update post counts (published, draft, unattached) in admin interface
- How to Display a List of Users Who Have Made at Least 1 Post?
- Find out who deleted a page or post?
- WordPress: How to get the current logged in author page URL?
- disable password protected page for logged users
- Force “Submit to review” when a post is updated
- Overview with latest edited posts and pages
- Navigation link to specific user page
- Get how many days since last post of the current user
- Hide comments awaiting moderation from user who submitted the comments
- Query All users that has post
- Limit number of posts a user can make per minute?
- How do I allow users to follow a post and then allow admins to email all users who have followed that post?
- wp_insert_post let users post to without login…broke
- Get user’s most published categories
- Allow anonymous users to post to my site for moderation
- disable column on post and user list
- how to find user ids of all commenters in a post
- How to list users and their post amount?
- Is there any way to allow users to access content before it’s published?
- UberMenu list current user’s posts as menu items
- Create post for every user?
- count the total number of comments the user has received for his published posts
- Restrict users post for himself
- How to allow logged in users to post anonymously
- Allow public to post on blog
- current post with current author
- How to verify wp user password by sql query in wp? [closed]
- Encountering “Wrong nonce. Action prohibitied.” when trying to alter User Role and unable to Post via WP Admin
- Users problem (multi-author plus multisite)
- How do I manage my users post before publish?
- How do I retrieve a users’ last 5 posts?
- Gather posts into a cart/lightbox and share with another user
- Assign published posts to another user automatically
- Add field to user meta table in database when link is clicked
- Hide comments and posts posted by other user
- Automatically create a default set of posts for each new registered user
- Summary of Posts by an User
- Display a list of users who have viewed the post you are viewing
- Check if current user has a post and that post has any term/s from a specific custom taxonomy outside the loop
- Echo Text If User Is Logged in But NOT the Author of post
- Deleted a user with administrator rights. Now all the data/content/images are lost. how to recover them back
- Show number of posts by logged in user
- Retrieve data from post meta meta_key having ‘_product_fq_image’ while having author_id and post type is PRODUCT
- Cannot select certain authors for posts after import
- How to limit post (Exception pages) for current user in each role in front end?
- How can get the last post date of the user?
- Is there a way to save different data when USER interacts with the same POST?
- How to display particular categorie’s post which associated to specific user?
- WordPress Delete Users from backend doesn’t work
- Allow users to post their videos to my wordpress website?
- Compare date of user’s last posts
- Add new post only in assigned category
- WordPress each user has each content for a page,how to do that?
- User rank in wordpress post
- Count how many posts a user has viewed
- Allow users to create their own page/s
- Get current user array with post string
- My posts section for logged in user
- Show Custom Post From Logged In Author
- Delete old post with new post
- How to handle dates, trying to calculate time since a post
- each user having category with their name and can add sub categories post in that category
- The post order is different for logged-in and non-logged-in users? [closed]
- User submitted post
- Automatically select category based on user role
- Undefined Function Fatal Error with Shortcode [closed]
- How to allow Contributors to edit their own posts, whilst still needing to be reviewed by an admin?
- Allow users to edit post without logging in
- Add custom Attachment Display Setting for images
- Rewriting post slug before post save
- User-Specific Timezones? Hack? Plugin?
- Post content being duplicated by the_content();
- How To Keep Posts from Being Displayed Two or More Times on My Homepage? [closed]
- How to access featured image?
- How to display category from recent posts?
- Best way to assign post position in a news site homepage? (no categories, no sticky posts)
- How do I restart my loop with get_next_post()?
- “Duplicate” Posts Appearing Since 3.1.2 Update
- Rename “post” to “article” throughout the admin back end [duplicate]
- Can I search posts and pages for css classes?
- Need to remove duplication content on home page in wordpress theme
- Disable auto-save and post revisions from inside a theme or plugin
- Refresh problem post is duplicated when page is submitted after page reload
- Migrate posts from category and sub-category via SQL
- Force fill all fields when creating a new post
- Display recent posts from portfolio
- How to get post with slug and exclude categories
- Categories Listing and Highlighting current category item
- In admin panel, use a form to create a post?
- WP_Query get posts in custom database table [duplicate]
- How to save template data into wp_post table (post_content column)
- Category URL to use same string as Post URL Permalink
- How to add content to the menu
- Multiple Custom Post Type loop logic
- Export Posts with specific custom fields by sql
- How to Post to Specific Pages?
- How to have more post in a page than in your home page
- Exclude a ‘portfolio’ custom category?
- How to delete posts with incorrect status