Last active
August 5, 2022 14:48
-
-
Save jchristopher/8488c91eb6c0d90922ec686865e23a2f to your computer and use it in GitHub Desktop.
Custom OrganizeWP Smart Group to lists Posts with no Comments
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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