get_results( $wpdb->prepare( "SELECT SQL_CALC_FOUND_ROWS follow_request.ID AS id, follow_request.post_date AS published, follow_request.guid, follow_request.post_status AS 'status', follower.post_title AS 'post_title', follower.guid AS follower_guid, follower.id AS follower_id, follower.post_modified AS follower_modified FROM {$wpdb->posts} AS follow_request LEFT JOIN {$wpdb->posts} AS follower ON follow_request.post_parent = follower.ID LEFT JOIN {$wpdb->postmeta} AS meta ON follow_request.ID = meta.post_id WHERE follow_request.post_type = 'ap_follow_request' AND (follower.post_title LIKE %s OR follower.guid LIKE %s) AND meta.meta_key = 'activitypub_user_id' AND meta.meta_value = %s ORDER BY %s %s LIMIT %d OFFSET %d", '%' . $wpdb->esc_like( $search ) . '%', '%' . $wpdb->esc_like( $search ) . '%', $user_id, $orderby, $order, $per_page, $offset ) ); $current_total_items = $wpdb->get_var( 'SELECT FOUND_ROWS()' ); // Second step: Get the total rows without the LIMIT $total_items = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(follow_request.ID) FROM {$wpdb->posts} AS follow_request LEFT JOIN {$wpdb->posts} AS follower ON follow_request.post_parent = follower.ID LEFT JOIN {$wpdb->postmeta} AS meta ON follow_request.ID = meta.post_id WHERE follow_request.post_type = 'ap_follow_request' AND meta.meta_key = 'activitypub_user_id' AND meta.meta_value = %s", $user_id ) ); return compact( 'follow_requests', 'current_total_items', 'total_items' ); } }