If you really want to make a WordPress query, you need to use $wpdb
that already offers a complete interface for everything you need.
Your query could be done as follows:
global $wpdb;
$id = $wpdb->get_var( "SELECT ID FROM $wpdb->posts WHERE post_type = 'photo' ORDER BY ID DESC LIMIT 1" );
Note that in this case I used $wpdb->posts
, since the installation of each one may not always have the prefix wp_
. Besides that if it were necessary to consult a different table than the standard WordPress should use something like:
{$wpdb->prefix}nome_da_tabela
Another thing I've changed in your query is that I just did it to get ID
, since it does not make sense to query multiple columns if you just need one.
Just because I needed only one value, I used the $wpdb->get_var()
method. This way you do not have to worry about extracting the value of an object or an array.
But generally for queries in WordPress posts you can use WP_Query
or get_posts()
(which creates an interface for WP_Query
).