【问题标题】:WordPress : Only variables should be assigned by referenceWordPress:只能通过引用分配变量
【发布时间】:2016-01-05 06:34:19
【问题描述】:

我正在使用这种方式在帖子中获取图片,例如:

$images =& get_children( 'post_type=attachment&post_mime_type=image&post_parent='.get_the_ID() );

它的工作很好,但在控制台中显示这个错误: 只有变量应该通过引用分配

如何解决?

【问题讨论】:

  • 你试过了吗:$images = get_children( 'post_type=attachment&post_mime_type=image&post_parent='.get_the_ID() );
  • 您可以通过引用变量、新语句或函数返回的引用传递。阅读更多here。只需删除&,您就会在$images 变量中获得可以使用的数组。
  • 是的,它的工作,,,谢谢

标签: wordpress


【解决方案1】:

错误来自 wordpress 执行 E_STRICT 规则背后的 PHP 配置。 您只能通过函数引用返回变量 - 仅此而已。

有关如何更改 php.ini 文件的更多信息(隐藏警告但不能修复原因) https://secure.php.net/manual/en/migrating5.errorrep.php

更多内容包括(我认为)您在此处所做的示例 - https://secure.php.net/manual/en/language.references.return.php .

【讨论】:

    猜你喜欢
    • 2020-10-21
    • 2017-10-24
    • 2023-03-28
    • 1970-01-01
    • 2017-06-03
    • 1970-01-01
    • 2013-06-21
    • 2017-06-06
    • 1970-01-01
    相关资源
    最近更新 更多