Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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?

share|improve this question

1 Answer 1

up vote 1 down vote accepted

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 );

share|improve this answer
    
For unknown reasons, using $wpdb->posts won't work here, but you were right about the extra underscore. –  Pippin Jul 20 '11 at 20:12

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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