Actually your function works as you described.
I copied your function into a page template on my site without modifying it at all. I tested it with my main user, which has posted, and it said I had posted.
Then I created a dummy user that has not posted. I tested the same page and it said I had not posted. I also posted a post backdated more than 30 days, and it still said I had not posted within the last 30 days.
All of that is by design.
A couple of points to keep in mind:
-
You aren’t specifying in your query which type of post is being retrieved. Are you sure that the user you are testing with hasn’t posted any type of post? i.e. a custom post type, a page, a contact form via a plugin, etc.
-
Your code is also always checking the currently logged in user. Make sure that’s what you want.
Related Posts:
- Use author author display name in permalink structure for pages and posts
- Possible to search by author name with default WordPress search function?
- Add admin bar link to edit author
- Authors details such as social media links, emails etc → Is this Meta or something else?
- Display the number of user comments
- Hide Author.php template from specific user role
- How to automatically remove links from WordPress Biographical Info?
- Commenter should see only his comments in wordpress
- Allow Post Author to be 0 on Update
- wp-comment author- url +, email filter hook
- check if author has published posts in custom post type, then send mail
- Disabling Author Page only for subscribers
- If no author posts, echo out some text
- Get post_author email for Zapier Integration
- Author social media aren’t shown on the page
- How To Display Author Popup on Entry Meta (Genesis Framework)?
- Author Page User id in functions.php for non login user
- Author info does not show up when author has no posts
- Show the online status of the current post’s author
- How to Insert A List of Posts in A Category Written by the Author into the Author Archive
- How to add user_registered time in human_time_diff() wordpress
- get php variable from functions php and echo it in theme template files [closed]
- Use AJAX in shortcode
- Remove Container Element From wp_nav_menu() Markup
- WordPress function like is_category for subcategory? is_subcategory?
- WordPress Theme Update Action?
- Using a private method as an action callback from within a class
- Auto close (hide) custom metabox / set default state
- Does WordPress Development Mode Exist (with not minified JS)?
- WP_Query in functions.php
- wp_delete_user with username
- what is the meaning of settings_fields()
- Organize functions.php
- How to activate “Description” metabox for menu item programmatically?
- Change labels on ‘Nickname’ and ‘Biographical Info’ in user-edit.php
- Edit the_content function
- Function to check if author has posted within the last x days
- write in functions.php
- How to set child post categories to parent post categories when updating parent post?
- get excerpt without images
- display 100 products per page on product category page [closed]
- WooCommerce add_action hook results in 500 error
- Advice: Template structure – php blocks in sidebar or someting else?
- Help to resolve Syntax error, unexpected ‘endwhile’ (T_ENDWHILE) [closed]
- wp_get_post_terms() returns WP_Error in functions.php but in template it works
- Removing the first image in content
- Make menu structure match page heirarchy on page parent change
- Global functions on WPMU
- Remove the deleted users avatar from list
- is_account_page() change to page slug
- woocommerce: change default setting > is_sold_individualy function
- Help with WP gallery function, wrap gallery in div
- set_post_thumbnail when user is not logged in
- Can you put a condition on add_image_size() depending on the width of the uploaded image?
- Force to use STRONG users password and implement rule to prevent REUSE [closed]
- Adding an external HTML link to a post thumbnail
- Overwriting the menu break points of twentysixteen in child theme
- Is there a WP function to get taxonomy name from taxonomy_term_id?
- Passing User_Fields to Contact form 7 [duplicate]
- How can this crude function be improved?
- Help With Creating Shortcode
- How to override woocommerce.css?
- How to set default post editor based on role?
- get_pages() Returns Only One Item
- Use a shortcode to display custom meta box contents
- Solved: redirect to another page using functions.php
- Getting the teaser text without overriding global variables
- Solution dealing with Child Theme / Parent theme functions
- Function to pull data from user meta not working
- referencing the current user in a page i created in wordpress
- Counting posts and trigger it [closed]
- Replace theme function
- How to access custom class methods from any include without using global
- Is it possible to use ‘wp_insert_post’ function within a for loop?
- save_post function keeps triggering: Warning: array_map(): Argument #2 should be an array… when restoring from trash
- More than one search results page template for two searches on site
- How do i create a search option for pdf’s only
- What is best practices to move the following code into a function?
- Redirect after login to current URL
- Restrict certain roles registrations by domain
- Replacing term/taxonomy archive pages with search queries
- Return ACF Field value function
- Best way to add image to recent posts widget?
- Issues with add_query_arg() not passing a variable
- wp_enqueue_script only works outside of action
- Automatically Populate Post Taxonomy Data Based on Post Author Meta Data?
- Force changing the Site Title and add link
- create submenu page – error function not found or invalid function name
- Get Value of Custom Field
- Undefined offset: 2
- Sorting date results from a query
- Using is_plugin_active within functions.php
- Add title & subtitle to shortcodes
- Button generate a random URL [closed]
- How to Delete Posts by title?
- How do I add functionality to images?
- Display function from functions.php in tag.php
- AJAX values converted to PHP Variables?
- Setcookie not setting cookies anywhere except admin
- WooCommerce, change “Add to Cart” to “Link to Product”, only for specific categories