错误:类 stdClass 的对象无法转换为字符串 -- implode() -- php
任何人都可以帮助我理解为什么我收到以下错误:
类 stdClass 的对象无法转换为字符串...(错误指向带有 implode(),< 的行/strong> 见下文)
当我运行以下函数时?
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;
我的目标
是返回一个字符串而不是一个数组。
也许必须以不同的方式处理从 SELECT 返回的数组?
提前致谢,
玛丽娜,
谢谢您的回答。我正在尝试显示从网上下载并将其保存在 WordPress 数据库中的网页,而不是帖子。
两个都 $webPageArticle = $wpdb->get_results( "从 $wpdb->posts WHERE ID=$id 中选择 post_content_long",ARRAY_N); 和 $webPageArticle = $wpdb->get_results( "从 $wpdb->posts WHERE ID=$id 中选择 post_content_long",ARRAY_A);
工作良好,并且 implode() 不再抱怨。但是,我没有得到真正的字符串,因为语句“echo $webPageArticle;”在屏幕上可视化单词“Array”。怎么
来的?
码头
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
正如 Codex 中所述,您可以将额外的第二个参数传递给 get_result() 以允许其返回数组而不是对象
返回一个可以操作的关联数组。
参考:
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: