首页 > 解决方案 > WP_Post 类的对象无法转换为字符串

问题描述

我想我可能会遇到与此处发布的问题类似的问题,但我不知道如何应用该解决方案/如果我真的遇到同样的问题。我很新,我不知道我可以用建议的解决方案做什么。在回答我的问题时,我希望你会非常详细。请逐步指导我。

当我激活这个插件时,这一切都开始了: Tin Canny LearnDash Reporting

它导致了这个错误:

WordPress database error Index column size too large. The maximum column size is 767 bytes. for query ALTER TABLE wp_posts ENGINE=INNODB made by activate_plugin, include_once('/plugins/tin-canny-learndash-reporting/tin-canny-learndash-reporting.php'), include_once('/plugins/tin-canny-learndash-reporting/src/uncanny-articulate-and-captivate/storyline-and-captivate.php'), TINCANNYSNC\\Init->__construct, TINCANNYSNC\\Init->check_upgrade, TINCANNYSNC\\Database->upgrade, call_user_func, TINCANNYSNC\\Database::create_table_snc_post_relationship\n, referer: https://www.lets-grow.today/wp-admin/plugins.php?plugin_status=all&paged=1&s

在主机/插件开发人员/reddit 用户之前的反馈之后,我尝试在 SQL 中运行此查询:

ALTER TABLE wp_posts ROW_FORMAT=DYNAMIC;

现在,当我在 Learndash (LMS) 中打开不属于课程或步骤的测验时,我遇到了这个新错误:

Backend log: PHP Recoverable fatal error: Object of class WP_Post could not be converted to string in /home/debXXXXXXX/domains/lets-grow.today/public_html/wp-content/plugins/sfwd-lms/includes/classes/class-ldlms-course-steps.php on line 910\n, referer: https://www.lets-grow.today/tasks-projects/3hv-y-ch-02-knowledge-of-history/quizzes/uk-02-history/

我尝试加载备份,但错误仍然存​​在。

这是第 910 行:

$steps_key = $post_type .':'. $post_id;

Reddit 上有人试图帮助说: $post_type不是字符串,也不能成为字符串。从哪里来$post_type

这可能是我的问题的答案,但我不知道如何处理答案:

$post_ID 是一个 WP_Post 对象。您的执行代码应该有效地使用 $post_ID->ID。

函数 save_new_post($post_ID) { print_r($post_ID); 死(); 退货

WP_Post 对象([ID] => ... 由 vancoder 提供

请注意,这取决于您使用的钩子。例如,如果你使用 publish_page 你会得到一个整数(这实际上是我困惑的根源)

标签: phpwordpressstring

解决方案


推荐阅读