I’m doing a QUIZ system, but I’m facing a problem that I dont know how to fix it.
I need to make a if
basically, where it will check if the current user has a post published, as the question title. It’s important to say that the posts are a specifically custom-post-type, so I need to check if there is a post with a certain post-type with the author-id equal to the current user ID.
Can someone help-me?
2 Answers
Using get_posts or WP_query with similar $args:
$args = array(
'post_type' => 'your_custom_post_type',
'author' => get_current_user_id(),
);
$wp_posts = get_posts($args);
if (count($wp_posts)) {
echo "Yes, the current user has 'your_custom_post_type' posts published!";
} else {
echo "No, the current user does not have 'your_custom_post_type' posts published.";
}