在wordpress页面上使用SQL

Using a plugin I'm able to use PHP on page by using [insert_php] as a tag however, whenever I try using SQL it doesn't seem to work. I tried using:

global $wpdb;
$prepared = $wpdb->get_row(
    "SELECT SiteID, SiteName
    FROM $wpdb->Site
        WHERE SiteID = 1");

echo $prepared->SiteName;
echo "test";

All I'm getting is test on the page and I've tested to see if my sql statement was at fault and it seems to be working fine so I'm guessing there's an issue with $wpdb or the way I'm outputting the data.

WordPress.org has a lot of detailed information in their reference.

I think attempting to refer to $wpdb->Site is a likely suspect for why your code is not working. You will need to know the exact fields in the table to pull your information.

Here is a reference for the wp_site table. I think you're actually looking for the 'domain' field, not 'sitename'.

Try replacing $wpdb->Site with the actual name of the table. I also get errors like that at first since $wpdb->table_name only works with the default wp tables.

EDIT It should be something like this: SELECT SiteID, SiteName FROM Site WHERE SiteID = 1