$wpdb->get_var not returning count
Question
I’m trying to do a count for pagination and its returning NULL why the query returns results correctly. In this case $total returns NULL which is not correct why? (I didn’t include the $args as they work)
$total_query = "SELECT COUNT(*) FROM (${args}) AS total_count";
$total = $wpdb->get_var( $total_query );
$items_per_page = 5;
$page = isset( $_GET['cpage'] ) ? abs( (int) $_GET['cpage'] ) : 1;
$offset = ( $page * $items_per_page ) - $items_per_page;
$results = $wpdb->get_results( $args . " ORDER BY user_registered DESC LIMIT ${offset}, ${items_per_page}" );
0
mysql
4 years
2020-03-07T19:56:25-05:00
2020-03-07T19:56:25-05:00 0 Answers
74 views
0
Leave an answer