Showing Counts on Comment List with Custom Query

Question

I have added a meta value to the comments-meta table that adds a custom ‘status’ type code (called ‘redacted’) to a comment. I have used the following code to display a link to display only those comments with a specific meta value on the edit-comments.php admin Comments page. This was done with the following code:

// add to the comment links at the top of the comments list admin page
    function my_comment_link_add($status_links) {
        $status_links['redacted']= "<a href="https://wordpress.stackexchange.com/questions/412509/?status=redacted">Redacted</a>";
        return $status_links;
        }
    add_filter("comment_status_links","my_comment_link_add");

// if clicked on the link, modify the comment query
if (isset($_GET['status']) AND ($_GET['status'] == 'Redacted')) {
    add_action('pre_get_comments', 'my_comment_redacted_list' );
}
function my_comment_redacted_list($query)
{
    global $pagenow;
   // if ( is_admin() && ('your-custom-page' === $pagenow) ) {
        $query->query_vars['meta_query'] = [
                    'relation' => 'AND',
            [
                'key' => 'redact',
                'value' => '1'
            ],
        ];
     
        return;     }

Clicking on the new ‘Redacted’ link displays the comments that have the ‘redact’ key in the comment_meta table.

But:

  1. the ‘Redacted’ link does not show the count of the custom query records found (when All comments are shown in the table).
  2. If I click on the ‘Redacted’ link, only the ‘redacted’ comments are shown on the list. But the ‘All’ link only shows the count of the custom query (the count of ‘redacted’ comments), not the total number of comments. (In fact, all of the counters on the links line only show the result of the custom query.)

Is there a more efficient way of doing this? How do I show the proper count for the ‘Redacted’ link on the ‘all comments’ table list. And how do I show the proper ‘All’ count when only the ‘Redacted’ comments are shown on the table list.

0
Rick Hellewell 1 month 2023-01-01T15:39:26-05:00 0 Answers 0 views 0

Leave an answer

Browse
Browse