Return number of items in a table with post id

I am trying to return the number of reviews for a given page ID, I have this so far:

<?php
global $wpdb;
$countreviews = $wpdb->get_var($wpdb->prepare("SELECT COUNT(ID) FROM $wpdb->wpcreviews     WHERE page_id = ID"));
echo 'Number Of Reviews ' . $countreviews . '';
?>

Its not working and I assume it’s the end part page_id = ID

Read More

How do I change the ending to that it searches the wpcreviews table for items with the current page ID, which is the same as my post ID?

Related posts

Leave a Reply

1 comment

  1. $countreviews = $wpdb->get_var( $wpdb->prepare( 'SELECT COUNT(ID) FROM ' . $wpdb->prefix . 'wpcreviews WHERE page_id = %d', get_the_ID() ) );