I figured it out using this previous post:
Issue with front-end ajax, getting a 302 redirect when accessing wp-admin/admin-ajax.php
Basically, I had added an action to prevent subscribers from seeing certain wordpress pages.
function limit_subscriber_access() {
$redirect = home_url( "https://wordpress.stackexchange.com/" );
if ( ! ( current_user_can( 'manage_options' ) || current_user_can( 'edit_posts' ) ))
exit( wp_redirect( $redirect ) );
}
This was causing the 302 redirect and preventing the $wpdb related code from executing. Here is what I added:
function limit_subscriber_access() {
$redirect = home_url( "https://wordpress.stackexchange.com/" );
if ( ! ( current_user_can( 'manage_options' ) || current_user_can( 'edit_posts' ) ) && !defined('DOING_AJAX'))
exit( wp_redirect( $redirect ) );
}
I tested and it seems to be working how I wanted.
Thanks to everybody who helped me try to figure it out!