Redwall Redwall - 1 year ago 52
PHP Question

I need to check if Current user is Author to Custom Post Type

I want to write a conditional statement (in pseudo below to explain)

IF current logged in user is 'Author' to a custom-post-type called 'farmers' {
// Do something
} else {
// Do something else

My code effort so far is

// Global variable for current 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 $posts = 0 {
// Do something
} else {
// Do Something else
} ?>

User can have the role "Author" in the system, but not necessarily have any posts. So I need to check the condition that this Author actually has a post. I am just not sure how to write that IF statement at the end of the code and looking for some help.


Answer Source

Use something like this

$query="select * from posts where type='farmers'";

//your code
//your code


// user have post
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download