Search code examples
phpmysqlwordpressbuddypress

Query Custom WordPress/buddyPress Table (PHP/MySQL)


I have been looking around and trying different things for a while and no luck.

Scenario: I have WordPress/BuddyPress and I added in a few new tables to the database through phpMyAdmin. I cannot run a successful query to them, yet I can to all the original tables. I have tried many things, this is my most recent try, still not working:

$b1_exc = $wpdb->get_results( $wpdb->prepare("SELECT * FROM memberbadge
WHERE 1") );

I would really appreciate a solution to add custom tables and be able to query them.

Thank you in advance!


Solution

  • It's probably a prefix problem. Try:

    $wpdb->get_results( "SELECT * FROM {$wpdb->prefix}memberbadge") );
    

    If you really need a WHERE clause and the variable comes from user input, then use prepare.