I'm using switch_to_blog() and restore_current_blog() to perform some functions across a multi site install. One of the things I'm trying to do is select a very specific post using get_row(). My function looks like this:

$prefix = $wpdb->prefix;
$tbl = $prefix;
$product = $wpdb->get_row("SELECT * FROM {$tbl}_posts WHERE ID = 4253");
print_r($product); exit;

The post with ID 4253 definitely exists, and I know for sure that the prefix is correct, however print_r returns absolutely nothing, nor does echo $product->post_title;

Any ideas?

1 Answer 1


Edit: You have an extra underscore in your table name, it becomes wp__posts in your case. Better use like how I have shown below :)

First, use table names like the following and try var_dump to see if it returns NULL. In case the Post ID doesn't exist, $product will be NULL, which only var_dump can show.

$product = $wpdb->get_row("SELECT * FROM $wpdb->posts WHERE ID = 4253"); var_dump( $product );

  • For unknown reasons, using $wpdb->posts won't work here, but you were right about the extra underscore.
    – Pippin
    Jul 20, 2011 at 20:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.