我想写一些简单的代码来确定用户是否是任何帖子的作者(如果他们的角色是作者,则不是这样)
我的尝试如下,但我无法弄明白
这是我的代码试试
<?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
} ?>
感谢您提供任何帮助指导
答案 0 :(得分:2)
怎么样:
if( $posts ) {
// Do something
}
else {
// Do Something else
}