It was the thing in the order of functions, and the check :
if(is_user_logged_in()){
$current_user = wp_get_current_user();
}
else {
$user_id = get_post_field( 'post_author', $post_id );
$current_user = get_userdata($user_id);
}
Related Posts:
- WordPress refuses to send mail, “…your host may have disabled the mail() function”
- WordPress “phpmailer_init” not working for me
- How do I override the Message-ID header of wp_mail function?
- WordPress new user / forgot password emails are broken
- wp_mail function timing out
- Why is my get_post_meta always empty
- Should I use wp_mail or PHP’s mail? [duplicate]
- Mail not sent when I set HTML headers
- Error when requesting password reset email – wp authentication
- Processing a subscription form with POST method?
- Different Webhost and using Google Mail server: Is there a better way than SMTP?
- wp_mail not sending
- Validate emails in array using foreach
- Redirect to another page after submission using wp_mail
- PHP 8, AJAX mail form to function.php doesn’t work
- How to retrieve the sender email with wp_mail()?
- wp_mail file attachment not being placed in upload folder?
- Website needs to be opened for wp_mail to work
- Notify users only on post publish
- Sending a custom form data in email through WP Mail Function
- Pass Variables or Variable Place-Holder from Editor to PHP
- Pass return-path additional parameter in wp_mail
- Send notification email to admin for every new post published
- Different SMTP based on domain
- Get page permalink in contact form
- comment_post (if comment is approved OR $comment_approved === 1) not working?
- Running SMTP Conditionally
- Including user data in “new user notification email”
- Cron not sending wp-mail()
- Email always ends up in spam
- Premature end of script headers: wp-mail.php?
- Adding action item to admin users table and sending email
- Wp_mail doesnt work
- get_post_meta is always empty when I use wp_mail
- wp_mail vs mail functions and header arrays
- Word press – JSPDF – Sending PDF as attachment from wp_mail – Special characters
- wp_mail – send emails after 24 hours from users registration
- Send emails to individual subscribers when CPT post is deleted (trashed)
- Send registration email to all admins
- What is the correct way to use WordPress functions outside WordPress files?
- Hide php Notices in Dashboard
- Shortcode to insert
- Calling a method from functions.php on a click of a button
- How to change featured content to a different tag in WordPress Twenty Fourteen?
- Using Echo in ShortCode – Stuck
- Two posts in same div – WP loop
- Compare two meta key values against each other inside the get_posts array?
- WordPress menu deletes when trying to add a hook
- Making Quote Plugin more efficient
- Different database query in function.php using mysqli
- How to show only a certain part of the entry title?
- Create shortcodes within foreach loop (using array)
- Programmatically add and remove woocommerce product category
- Get image’s size name from it’s dimension
- wp_enqueue_scripts leads to error
- How can I get the values of my WordPress $wpdb query in Jquery?
- How create a Shortcode with hover and complex options
- Change CSS based on is_user_logged_in
- How to hook code to show after the_content?
- Run a code only on theme activation only during first activation
- Shortcode from a function not working
- Creating WordPress Shortcode with Variable
- Catchable fatal error: Object of class stdClass could not be converted to string
- Get title attribute from galleries
- How to add text to the start of all comments?
- unknown issue in ‘header.php’ preventing theme from displaying fully
- random display categories – change url
- Display child page content of a specific parent on home page
- Generate responsive post thumbnails of same size
- Change out put of the_post_thumbnail in PHP
- Styling an “active” link outside of WordPress default menu
- WordPress permalink issue
- Any way to hide a blog posts text if it’s longer than let’s say 300 characters
- how to make wordpress user submit form once?
- Update PHP version of WordPress (internal hosting)
- Multiple Tag Filtering
- Is it possible to change the get_posts() or wp_query() function to alter the results that are returned?
- Need to show 7 posts from actual date
- How to reload a php script, using AJAX and jQuery
- Notice: Undefined variable
- Make wp_editor required
- Add the shortcodes from the enfold theme to the other theme
- I need to edit a widget, with no dashboard access
- Get the total Author Favorited posts
- How to properly create multiple conditions to redirect users roles to different pages
- unable to add category in creating post dynamically
- WordPress WPDB::insert 13th param is always blank (only if format)
- MySQL query in WordPress with AJAX
- enumerating custom taxonomies?
- Change colour of table td based on value
- WordPress styling recent post
- Headers Already Sent
- If or/and statement advanced custom fields [closed]
- Add specific phrase after every product title including the discounted price? [closed]
- Product Category Page in Full Width
- After declaring woocommerce theme support products are no longer displayed
- PHP how to submit array elements to database
- Ajax – how to use XMLHttpRequest in wordpress
- Running a long script in PHP
- Can’t assign menu parent id or menu item breaks