Skip to main content
replaced http://wordpress.stackexchange.com/ with https://wordpress.stackexchange.com/
Source Link

$row doesn't look like you think it does. $wpdb->get_results will by default return an array of objects. Your code-- 'post_title' => $row['Title']-- treats an object like an array and should generate a Fatal Error, which you'd see if you had debugging enableddebugging enabled.

Fatal error: Cannot use object of type stdClass as array in ...

You need object syntax. Try (using a Core table):

$rows = $wpdb->get_results( "SELECT * FROM wp_posts");
foreach ($rows as $row) {
  // echo $row['post_author']; // doesn't work
  echo $row->post_author; // works
  echo '<br>';
}

$row doesn't look like you think it does. $wpdb->get_results will by default return an array of objects. Your code-- 'post_title' => $row['Title']-- treats an object like an array and should generate a Fatal Error, which you'd see if you had debugging enabled.

Fatal error: Cannot use object of type stdClass as array in ...

You need object syntax. Try (using a Core table):

$rows = $wpdb->get_results( "SELECT * FROM wp_posts");
foreach ($rows as $row) {
  // echo $row['post_author']; // doesn't work
  echo $row->post_author; // works
  echo '<br>';
}

$row doesn't look like you think it does. $wpdb->get_results will by default return an array of objects. Your code-- 'post_title' => $row['Title']-- treats an object like an array and should generate a Fatal Error, which you'd see if you had debugging enabled.

Fatal error: Cannot use object of type stdClass as array in ...

You need object syntax. Try (using a Core table):

$rows = $wpdb->get_results( "SELECT * FROM wp_posts");
foreach ($rows as $row) {
  // echo $row['post_author']; // doesn't work
  echo $row->post_author; // works
  echo '<br>';
}
Source Link
s_ha_dum
  • 65.5k
  • 13
  • 84
  • 174

$row doesn't look like you think it does. $wpdb->get_results will by default return an array of objects. Your code-- 'post_title' => $row['Title']-- treats an object like an array and should generate a Fatal Error, which you'd see if you had debugging enabled.

Fatal error: Cannot use object of type stdClass as array in ...

You need object syntax. Try (using a Core table):

$rows = $wpdb->get_results( "SELECT * FROM wp_posts");
foreach ($rows as $row) {
  // echo $row['post_author']; // doesn't work
  echo $row->post_author; // works
  echo '<br>';
}