Skip to content

Commit 0b6ad50

Browse files
kendafik1sul1
andcommitted
Lighter way of counting submissions on plugin dashboard (#174)
* Lighter way of counting submissions on plugin dashboard Previously the dashboard fetched all posts for every form and only after that the submissions were counted. This does a lighter query that only returns the amount of submissions. Co-authored-by: Christian Nikkanen <me@kisu.li>
1 parent 9a57026 commit 0b6ad50

1 file changed

Lines changed: 4 additions & 8 deletions

File tree

classes/class-cpt-wplf-form.php

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -316,16 +316,12 @@ public function custom_columns_display_cpt( $column, $post_id ) {
316316
}
317317
if ( 'submissions' === $column ) {
318318
// count number of submissions
319-
$submissions = get_posts( array(
320-
'post_type' => 'wplf-submission',
321-
'posts_per_page' => -1,
322-
'meta_key' => '_form_id',
323-
'meta_value' => $post_id,
324-
'suppress_filters' => false,
325-
) );
319+
global $wpdb;
320+
$query = $wpdb->get_row( 'select count(*) as amount from ' . $wpdb->postmeta . ' where meta_key = "_form_id" and meta_value = "' . absint( $post_id ) . '"' );
321+
$submissions = $query->amount;
326322
?>
327323
<a href="<?php echo esc_url_raw( admin_url( 'edit.php?post_type=wplf-submission&form=' . $post_id ) ); ?>">
328-
<?php echo count( $submissions ); ?>
324+
<?php echo esc_html( $submissions ); ?>
329325
</a>
330326
<?php
331327
}

0 commit comments

Comments
 (0)