I want to write some simple code to figure out if the user is the author of any posts (Not if their role is author)
My attempt is as follows but I can’t figure it out
- I got the userID (set it to current in global header)
- I have created a query to for custom-post-type and author
- I have got all the current posts from the query
- I have added an IF statement (Which I CANT seem to get right)
Here is my code try
<?php
// Global variable for current user ID
$user_ID;
// Create a new WP query object
$my_query = new WP_Query( array(
'post_type' => 'farmers',
'author' => $user_ID
));
// Get all the current user posts from the query object
$posts = $my_query->posts;
IF There are Posts (Not sure how to write this line) {
// Do something
} else {
// Do Something else
} ?>
Thanks for any help guidance
How about: