我想写一个条件语句(下面用伪来解释)
IF current logged in user is 'Author' to a custom-post-type called 'farmers' {
// Do something
} else {
// Do something else
}
到目前为止,我的代码工作是
<?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 $posts = 0 {
// Do something
} else {
// Do Something else
} ?>
用户可以在系统中拥有“作者”角色,但不一定有任何帖子。所以我需要检查这个作者实际上有一个帖子的条件。我只是不确定如何在代码末尾编写该 IF 语句并寻求帮助。
谢谢