Skip to content

Instantly share code, notes, and snippets.

@aryanrajseo
Created September 23, 2023 22:37
Show Gist options
  • Save aryanrajseo/a23b3eb246a6efc8df15ad92a9eb2e24 to your computer and use it in GitHub Desktop.
Save aryanrajseo/a23b3eb246a6efc8df15ad92a9eb2e24 to your computer and use it in GitHub Desktop.
author reviewer.php
function reviewed_by_helper() {
$author_id = get_field('reviewed_by');
// Check if the author has published posts
$author_has_posts = false;
if ($author_id) {
$author_has_posts = get_posts(array(
'author' => $author_id,
'posts_per_page' => 1, // Check for at least 1 post
'post_type' => 'post', // Adjust post type if needed
'post_status' => 'publish',
));
}
if ($author_has_posts) {
$user_info = get_userdata($author_id);
$user_name = $user_info->display_name;
$user_url = get_author_posts_url($author_id);
return '<a href="' . $user_url . '">' . $user_name . '</a>';
} else {
$user_info = get_userdata($author_id);
$user_name = $user_info->display_name;
return $user_name; // Show author's name as plain text
}
}
add_shortcode('reviewed_by', 'reviewed_by_helper');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment