Skip to content

Instantly share code, notes, and snippets.

@jchristopher
Last active August 5, 2022 14:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jchristopher/8488c91eb6c0d90922ec686865e23a2f to your computer and use it in GitHub Desktop.
Save jchristopher/8488c91eb6c0d90922ec686865e23a2f to your computer and use it in GitHub Desktop.
Custom OrganizeWP Smart Group to lists Posts with no Comments
<?php
// Custom OrganizeWP Smart Group to lists Posts with no Comments.
// @link https://organizewp.com/docs/smart-groups/
class MyOwpPostsNoComments extends \OrganizeWP\SmartGroup {
function __construct() {
$this->name = 'no_comments';
$this->label = 'No Comments';
}
// Output the markup for this Smart Group.
function render() {
$entries = get_posts( [
'post_type' => 'post',
'comment_count' => 0,
'posts_per_page' => 5,
'order' => 'DESC',
'orderby' => 'modified',
] );
$entries = array_filter( $entries, function( $entry ) {
return current_user_can( 'edit_post', $entry->ID );
} );
?>
<?php if ( empty( $entries ) ) : ?>
<p class="description">Nothing to display! 🎉</p>
<?php else : ?>
<ul>
<?php foreach ( $entries as $entry ) : ?>
<li>
<a href="<?php echo esc_url( get_edit_post_link( $entry->ID ) ); ?>">
<?php echo esc_html( $entry->post_title ); ?>
</a>
</li>
<?php endforeach; ?>
</ul>
<?php endif;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment