can anybody help me understand why I get the followint error:
Object of class stdClass could not be converted to string in… (the error is pointing to the line with implode(), see below)
when I run the following function?
function selectFullArticle () {
global $wpdb;
$id=get_the_ID();
$webPageArticle = $wpdb->get_results( "SELECT post_content_long FROM $wpdb->posts WHERE ID=$id" );
$webPageArticle= implode(" ",$webPageArticle);
return $webPageArticle;
}
My aim is to return a string and not an array.
Maybe the array returned from a SELECT must be treated in a different way?
Thanks in advance,
Marina
Thanks for your answers. I am trying to display a webpage that I downloaded from the web and saved it in a wordpress database, and not a post.
Both
$webPageArticle = $wpdb->get_results( “SELECT post_content_long FROM $wpdb->posts WHERE ID=$id”,ARRAY_N);
and
$webPageArticle = $wpdb->get_results( “SELECT post_content_long FROM $wpdb->posts WHERE ID=$id”,ARRAY_A);
work well and implode() does not complain anymore. However, I do not get a real string, because the statement “echo $webPageArticle;” visualizes the word “Array” on the screen. T
how come?
marina
As read in Codex, you can pass an additional second parameter to get_result() to allow it to return an array instead of an object
returns an associative array you can then manipulate.
Reference:
If I figured it right and you want the post content only, use this: